Random annoyance
    Shari 
    gypsyware at earthlink.net
       
    Fri May  9 15:46:00 EDT 2003
    
    
  
I've just discovered an annoyance in the random() function.  (And 
according to the docs, it is not a bug.)
random(0) produces the result of "1"
One would assume that random(0) would always produce 0.
Why would one want to get random(0), you ask?
If 0 is a variable, which could be any number, and you write a 
mathematical function, assuming that if the variable is 0, the end 
result of the function will also be zero, the function fails.
It is quicker to let the result be 0, which affects nothing, than to 
say "if the variable > 0 then... run the function"
The following failed when item 17 of terrData was 0:
add round((random(item 17 of terrData)) * multiplier) to \
               item 56 of line x of gStats
Had to go thru and add a whole slew of "if..." statements to the code.
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.
It would still be very nice for random(0) to = 0
Math is not an entity where one wants unexpected results.
Shari C
-- 
--Shareware Games for the Mac--
http://www.gypsyware.com
    
    
More information about the metacard
mailing list