perl -e 'sysread(STDIN, $r, 4); print unpack("L", $r)."\n"' < /dev/random
prints a random number between 0 and 2^32-1
replace the 4 and L to get different ranges:
2, S gives 0 to 65535
1, C gives 0 to 255
On Sat, Apr 28, 2001 at 12:46:58PM +0100, kevin lyda wrote:
> On Sat, Apr 28, 2001 at 11:34:18AM +0100, Conor Daly wrote:
> > Errm, so, how do I get numbers form /dev/random? dd gives me ascii
> > garbage, so does cat. Do I need to write a c proggie to read and what
> > should I read then?
>> an ugly pipeline:
>> dd if=/dev/urandom bs=10 count=1 2> /dev/null| od -x | sed 's/^[^ ]* *//'
>> play with flags to od to change the radix, change the bs= setting for dd
> to get different sized numbers. oh, and i used /dev/urandom to generate
> the numbers as it always returns the amount requested (at the price of
> less randomness).
>> kevin
>> --
>kevin at suberic.net CERT CA-96.13/NiftyGreenShield: ... Impact:
> fork()'ed on 37058400 Non-privileged primitive users can cause the
> meatspace place: home total destruction of your entire invasion fleet
>http://suberic.net/~kevin and gain unauthorized access to files. ...
>> --
> Irish Linux Users' Group: ilug at linux.ie>http://www.linux.ie/mailman/listinfo/ilug for (un)subscription information.
> List maintainer: listmaster at linux.ie
--
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!