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$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
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. -cghost23while(@whatever) { s/blah/rwg()/ge; }
In reply to random number generation problem by cghost23
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |