You might want to see perldoc -f srand # PERL random seed documentation.
srand EXPR srand Sets the random number seed for the "rand" opera- tor. If EXPR is omitted, uses a semi-random value supplied by the kernel (if it supports the /dev/urandom device) or based on the current time and process ID, among other things. In versions of Perl prior to 5.004 the default seed was just the current "time". This isn't a particularly good seed, so many old programs supply their own seed value (often "time ^ $$" or "time ^ ($$ + ($$ << 15))"), but that isn't necessary any more.
In fact, it's usually not necessary to call "srand" at all, because if it is not called explicitly, it is called implicitly at the first use of the "rand" operator. However, this was not the case in version of Perl before 5.004, so if your script will run under older Perl versions, it should call "srand".
Note that you need something much more random than the default seed for cryptographic purposes. Checksumming the compressed output of one or more rapidly changing operating system status programs is the usual method. For example:
srand (time ^ $$ ^ unpack "%L*", `ps axww | gzip`);
<snip> etc.
You should be able to write similar code in C.
Amish.
Shailesh wrote:
Good point. Caveat: But based on philips advice two pieces of code.