Do you mean you fed those numbers to srand something like this:

~$ perl -wle 'srand(12345); for (1..3) {print rand(5);}' 1.12664256398149 4.59591534266778 1.03420626624091 ~$
and got the same output for each seed?

Two obvious possibilities:

  1. Your installation is broken
  2. your code didn't use the seed properly

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.