Random annoyance
dan johnson
danjohnson at 37.com
Mon May 12 18:18:00 EDT 2003
<Shari wrote>
[snip]
random(0) produces the result of "1"
One would assume that random(0) would always produce 0.
Even though the docs claim random(x) will always produce a number between 1 and x (and that x must be a positive integer), I tried random(-10) and got (-3) which was cool.
Shari,
It is clear that you read the MetaTalk entry for random, and likewise it is clear that you chose to try to use the function outside of its clearly documented scope.
Although the random function appears to behave as expected for any integer values that are not 0, technically, you are on dangerous grounds when using arguments that are less than 1. The behavior of the function for arguments less than 1 COULD be changed in future engine releases, resulting in your code breaking.
Zero is not a positive integer, and the fact that the function returned expected values for negative integers (and no, it really is NOT "cool" that it does!) is actually NOT the behavior that I would expect, but rather I would expect the function to return an error instaed of returning any value at all for arguments less than 1. So, according to the MetaTalk entry, one would NOT assume that random(0) would return 0 simply because all other arguments behave as intuitively expected rather than as explicitly defined in the docs.
"The random function returns a positive integer between 1 and <maxvalue> (which itself must be a positive integer)."
Because the smallest possible positive integer is 1, the smallest number that the random function can return is the positive integers between 1 and 1, which is 1.
DJ
------------------------------------------------------------
http://Game.37.com/ <--- Free Games
http://newJoke.com/ <--- J O K E S ! ! !
More information about the metacard
mailing list