in reply to Re-assign value to subroutine
rand returns a random1, uniformly distributed number. To quote the documents, "Returns a random fractional number greater than or equal to 0 and less than the value of EXPR. (EXPR should be positive.) If EXPR is omitted, the value 1 is used. Currently EXPR with the value 0 is also special-cased as 1 - this has not been documented before perl 5.8.0 and is subject to change in future versions of perl."
So, if you pass 0 to rand(), it currently returns a value, x|0 ≤ x < 1. I believe it does the same think if you pass undef to rand, but RTFM2. How you handle your value of number (incidentally,
is not valid; I'm guessing you meant to write:$my number = 10;
but I'm sure you noticed the error message from perl!) depends on what you want to do. Possibly, something likemy $number = 10;
may suffice, but I think that it most likely won't.$value = $user_input or 10; $x = rand($value);
Now, if you want to guarantee that rand always returns the same sequence of values, you've got to explicitly seed it, using srand. Once.
2The manual is definitely a worthwhile read, too. As an old connoisseur of computing documents, Perl's is definitely deserving of accolades.
emc
Information about American English usage here and here.
Any Northeastern US area jobs? I'm currently unemployed.
|
|---|