Do you mean you fed those numbers to srand something like this:
and got the same output for each seed?~$ perl -wle 'srand(12345); for (1..3) {print rand(5);}' 1.12664256398149 4.59591534266778 1.03420626624091 ~$
Two obvious possibilities:
Of course, there are countless other possibilities depending on just what you actually did.
But we can't see your code. And since we can't see it, it's really hard to know how to help you fix your problem. Maybe you should post the code (and read On asking for help and How do I post a question effectively? and maybe even I know what I mean. Why don't you?.
In fact, the only question I can answer with any confidence is the "bug?" question... and the answer to that is "no."
As to the "best way" to use srand? Well, it depends on what you're going to do with its output. But (sigh!), you didn't tell us that either. (However, for that, you might want to read perldoc -f srand whence this snippet comes:
You can call srand($seed) with the same $seed to reproduce the same sequence from rand(), but this is usually reserved for generating predictable results for testing or debugging. Otherwise, don't call srand() more than once in your program.
In reply to Re: srand producing the same sequence of random numbers
by ww
in thread srand producing the same sequence of random numbers
by e_c
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |