Logic shuffle

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Logic shuffle
# 1  
Old 04-25-2017
Logic shuffle

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,
# 2  
Old 04-25-2017
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
This User Gave Thanks to jim mcnamara For This Post:
# 3  
Old 04-26-2017
do we have anything with awk please?
# 4  
Old 04-26-2017
Quote:
Originally Posted by Indra2011
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.
Code:
       rand   random number on (0,1)

       srand  sets seed for rand and returns the previous seed.

       int    truncates to an integer value

Code:
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...
Login or Register to Ask a Question

Previous Thread | Next Thread

1 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to shuffle odd and even columns?

Is there any way to place each even column name infront of its odd column using awk or others? input Ab name MGH26 B04 MGH26 B05 output name_Ab B04_MGH26 B05_MGH26 (4 Replies)
Discussion started by: quincyjones
4 Replies
Login or Register to Ask a Question