cghost23 has asked for the wisdom of the Perl Monks concerning the following question:
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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: random number generation problem
by tadman (Prior) on Apr 27, 2001 at 01:20 UTC | |
by cghost23 (Novice) on Apr 27, 2001 at 01:39 UTC | |
by tadman (Prior) on Apr 27, 2001 at 01:49 UTC | |
|
Re: random number generation problem
by tadman (Prior) on Apr 27, 2001 at 01:15 UTC | |
by merlyn (Sage) on Apr 27, 2001 at 01:17 UTC | |
by tye (Sage) on Apr 27, 2001 at 02:07 UTC | |
by tadman (Prior) on Apr 27, 2001 at 02:17 UTC | |
by arturo (Vicar) on Apr 27, 2001 at 01:21 UTC |