On 02/04/2011 08:48 PM, Melikamp T. Medley wrote: > Hi! > > I want to generate pseudo-random integers from a shell, and I wonder if > coreutils can be used to do that. I really like randint.c , and I > basically want a shell front end to randint_choose. Or is there a > standard way to do this I am not aware of?
If you don't mind using bash extensions, evaluating $RANDOM is the fastest way to access a pseudo-random number from the shell. Or, several utilities provide random numbers, such as awk with its rand() function, or perl. Using just coreutils, though, I'm afraid your options are slim. You could use 'seq 0 9 | sort -R | head -n1' (or use shuf instead of sort -R) to generate one random number at a time, but that gets expensive. Or, if you don't mind limiting yourself to 62**6 values (instead of the more traditional 2**32), you could do 'mkdir tmp; mktemp -u -p tmp XXXXXX'. But that's the extent of coreutils' randomness exposed to the user. -- Eric Blake [email protected] +1-801-349-2682 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
