For cases when you can't, or don't want to, rely on an external module, this is quick, simple, and good enough for non scientific computing:
sub make_random_generator {
    my ($seed, $min, $max) = @_;
    # DO NOT CHANGE THESE
    my $a = 7 ** 5;
    my $m = (2 ** 31) - 1;
    # if seed was zero this generator will return zeros 
    # forever, set it to some arbitrary value
    if ($seed == 0) { $seed = 12345678; }
    unless (defined $min) { $min = 0; }
    unless (defined $max) { $max = $m; }
    if ($max < $min) {
        my $t = $min;
        $min = $max;
        $max = $t;
    }
    return sub {
        $seed = ($a * $seed) % $m;
        # "scale" $seed to the range ($min,$max)
        return int ((($seed / $m) * ($max - $min)) + $min);
    }
}
use it like this:
for my $seq_n (1..10) {
    print "random sequence with seed $seq_n:\n";
    my $gen = make_random_generator(rand, 0, 1000);
    print join ", ", map { $gen->() } 1 .. 10;
    print "\n";
}
this will return the same 10 pseudo random sequences every time you run it.

In reply to Re: Generating Repeatable Pseudorandom Sequences by Anonymous Monk
in thread Generating Repeatable Pseudorandom Sequences by mp

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.