i am writing code that will generate a given number of random characters and stuff them into a variable. here is the relevant code:
$minlength=5; $maxlength=15; $rlength=$minlength+=int(rand($maxlength)); @vchars=(a..z,A..Z,0..9); while(length($newvar) < $rlength) { $char=$vchars[int(rand($#vchars))]; $newvar.=$char } print $newvar
so basically $rlength holds a random whole number between 5 and 15 and @vchars holds the characters i want to use to generate the random word..then as long as $newvar is less than $rlength ($newvar is 0 at this point), a number between 0 and the number of characters in @vchars is generated and used as the array subscript for @vchars (effectively selecting a random element from @vchars). the result of this is assigned to $char, then $char is appened to $newvar...this repeats if $newvar is less than the random length...HOWEVER..if i do
while(@whatever) { s/blah/rwg()/ge; }
somewhere else in the code, where rwg is the name of the subroutine that contains the random word generation code at the top...instances of 'blah' get replaced with the same string of random characters, just of variable length. like 'blah blah' would become 'jhGsdF jhGs'. it seems the random element selection code only runs once or something..it just changes the length. this has been bothering me for days. thanks a lot. -cghost23

In reply to random number generation problem by cghost23

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.