75. Random numbers not including zero
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
There are times when you may want to generate a random number, which can be
positive or negative, but which must not include zero. Alternatively, you may
wish to multiply something by -1 or +1 at random, perhaps to determine which
way a monster will turn in a maze etc..
An easy way to generate -1 or +1 is with Z=SGN(RND) , (the brackets are
optional). RND on its own generates a number between -2147483648 and
+2147483647, so its SGN can only be -1, 0 or +1. Since the likelihood of RND
generating zero is about one in 4000 million, the result for all practical
purposes is always -1 or +1! To generate a random number between say, -9 and
+9 , but not including zero, you could use Z=RND(9)*SGN(RND). Thanks to
James Slater for passing this idea on.