Sponsored Content
Full Discussion: Logic shuffle
Top Forums UNIX for Beginners Questions & Answers Logic shuffle Post 302996459 by wisecracker on Wednesday 26th of April 2017 12:48:37 PM
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...
 

We Also Found This Discussion For You

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
SHUFFLE(1)						    BSD General Commands Manual 						SHUFFLE(1)

NAME
shuffle -- print a random permutation of the command line arguments SYNOPSIS
shuffle [-0] [-f filename ...] [-n number] [-p number] [arg] [...] DESCRIPTION
The shuffle program prints a random permutation (or ``shuffle'') of its command line arguments. This can be useful in shell scripts for selecting a random order in which to do a set of tasks, view a set of files, etc. If the -f option is given, the data is taken from that files' contents or if the filename is - ``stdin''. If the -n option is given, its argument is treated as a number, and the program prints a random permutation of the numbers greater than or equal to 0 and less than the argument. If the -p option is given, its argument is treated as a number, and the program prints that number of randomly selected lines or arguments in a random order. The -0 option changes the field separator character from to , so that the output is suitable to be sent to xargs(1) (to handle filenames with whitespace in them). EXAMPLES
$ shuffle a b c d c b d a $ shuffle -p 1 a b c d d $ shuffle -n 4 -p 2 0 3 SEE ALSO
jot(1), random(6) HISTORY
The shuffle program first appeared in NetBSD 1.4. AUTHORS
Written by Perry E. Metzger <perry@piermont.com>. BSD
February 18, 2009 BSD
All times are GMT -4. The time now is 05:07 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy