Hi,
Is there any way I can shuffle the numbers randomly. I have been trying to google and I found lots of 'generator' but is it possible to find the background logic to create randomness?
Thanks,
Hi,
Is there any way I can shuffle the numbers randomly. I have been trying to google and I found lots of 'generator' but is it possible to find the background logic to create randomness?
Thanks,
Some shells like bash have a pseudorandom random number generator.
Which is more than adequate to simulate dealing from a deck of cards.
Here is documentation on using the $RANDOM
variable to do what you asked:
$RANDOM: generate random integer
Here are examples of what goes on behind the scene:
Random number generator (included) - Rosetta Code
do we have anything with awk please?
Just look at the man awk
file.
From 'man awk' on OSX 10.12.4, default bash terminal.
rand random number on (0,1)
srand sets seed for rand and returns the previous seed.
int truncates to an integer value
Last login: Wed Apr 26 17:45:25 on ttys000
AMIGA:amiga~> awk 'BEGIN { print int(rand(srand)*17); }'
14
AMIGA:amiga~> awk 'BEGIN { print int(rand(srand)*17); }'
12
AMIGA:amiga~> awk 'BEGIN { print int(rand(srand)*17); }'
12
AMIGA:amiga~> awk 'BEGIN { print int(rand(srand)*17); }'
1
AMIGA:amiga~> awk 'BEGIN { print int(rand(srand)*17); }'
7
AMIGA:amiga~> awk 'BEGIN { print int(rand(srand)*17); }'
7
AMIGA:amiga~> awk 'BEGIN { print int(rand(srand)*17); }'
5
AMIGA:amiga~> awk 'BEGIN { print int(rand(srand)*17); }'
8
AMIGA:amiga~> awk 'BEGIN { print int(rand(srand)*17); }'
12
AMIGA:amiga~> awk 'BEGIN { print int(rand(srand)*17); }'
10
AMIGA:amiga~> _
Hope this helps...