Same thing, but using an environment variable.

Here is the Makefile:

> cat Makefile SEED := ${shell perl -e 'print int rand 10_000'} .EXPORT_ALL_VARIABLES: .PHONY: all all: @perl proc0 @perl proc1

Here is the 1st script:

> cat proc0 use warnings; use strict; if (exists $ENV{SEED}) { srand $ENV{SEED}; } else { die "Error: need a seed.\n"; } print "$0 ", rand, "\n";

Here is the 2nd script:

> cat proc1 use warnings; use strict; if (exists $ENV{SEED}) { srand $ENV{SEED}; } else { die "Error: need a seed.\n"; } print "$0 ", rand, "\n";

Now run it a few times:

> make proc0 0.0394185183840854 proc1 0.0394185183840854 > make proc0 0.821407354044826 proc1 0.821407354044826 > make proc0 0.697487873098911 proc1 0.697487873098911

In reply to Re: Generating same seed between 2 processes by toolic
in thread Generating same seed between 2 processes by alih110

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.