Hyperiris, if you want to iterate through regex matches in your while condition you'll need to use the /g modifier. Also, using $seed as a variable name for a variable which isn't being used to seed the srand function (but is instead being used as the rand() argument) only adds confusion. Lastly, unless you have need to reproduce results with a given seed (that is, a seed for the srand() function), then you want to call srand() only once prior to the loop (and with recent perl's, you don't really need to call srand() at all).

The reason you are getting the same $rndrslt everytime is that your $edtpost string starts with roll=1, setting $seed to 1, and thus your call to int(rand($seed)) + 1 is always going to return 1. Please see the following documents: rand and srand.


In reply to Re: rand() problems by danger
in thread rand() problems by Hyperiris

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.