[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: rand random. You've got to be kidding

Christopher Coleman-Smith

11/28/2006 6:12:00 PM

why not seed it from /dev/random/ in C/++ you'd do something like this:

unsigned int seed
FILE *devrandom = fopen("/dev/random", "r");
fread(&seed,sizeof(seed),1,devrandom);

then pass the seed to rand, using the time itself is a bit dubious if
you want a strong set of random numbers, not a good idea for statistical
research / cryptography i fear.



Smgspices@aol.com wrote:
> Surely it must be possible to initialize rand with current date and time.
> Documents seem to indicate this is done with rand(0) or srand with no value. I
> have tried both methods and I get the same tired old sequence of numbers. I
> would write my own random number generator except I don't know how to get a
> numeric value out of Time.
>
> Charles Gray
>
>


1 Answer

Eric Hodel

11/28/2006 6:40:00 PM

0

On Nov 28, 2006, at 1011 , Christopher Coleman-Smith wrote:

> why not seed it from /dev/random/

rand() is seeded by /dev/urandom by default.

--
Eric Hodel - drbrain@segment7.net - http://blog.se...
This implementation is HODEL-HASH-9600 compliant

http://trackmap.rob...