Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Static value of a random variable

Status
Not open for further replies.

stauntx

Programmer
Joined
Apr 19, 2007
Messages
2
Location
CA
sub fR {
return int(rand(@_[1] - @_[0] + 1)) + @_[0];
}

$iRandom = fR(0, 19);

I'm using this code, and, every time I try to use $iRandom, it generates a new value, I need it to generate a random value once and maintain that value; how would I do this?
 
if you don't call the sub routine again then the value should remain the same for the life of the script.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
I assumed that was true also, it doesn't seem to be the case unfortunately. =\
 
Can you post the script.. because (like Kevin said) if you only do that the part of script posted above I don't see why it would change.
 
it is the case or all perl scripts would be in big trouble if variables could change value for no reason.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top