|go ahead... be a heretic|
rand / srandby jbrugger (Parson)
|on Oct 24, 2006 at 07:17 UTC||Need Help??|
jbrugger has asked for the
wisdom of the Perl Monks concerning the following question:
Dear monksI need your help again.
For a tracking number, i generate random keys, with a length of 8 characters. The code i use is the following:
The problem is the following:
If i use srand at the beginning of the module, it will create the same keys after some time again.
If i use srand(time), this also happens, so i've put it in the sub Gencode.
As the documentation of srand says, i should not do this, and next, the same keys were generated after some time again.
I searched Pelmonks, google, and came up with the above solution, using srand (time ^ $$ ^ unpack "%L*", `ps axww | gzip`);
This is 'slow', and i wonder why (mod) perl does not genterate true random codes, in the above code there should be enough space to generate lots of different keys without having collisions.
So the question is, how do i properly create random keys as described above
Thanks for all your help, i'll have to look into one of the solutions.
The thing (i think!) makes it difficult, is the fact that we preload all our modules into apache.
If the process is started and srand is called, i think the child process of apache uses the same seed (please correct me if i'm wrong here), thus generates the same random keys again.
"We all agree on the necessity of compromise. We just can't agree on when it's necessary to compromise." - Larry Wall.