Random of zero

Raymond E. Griffith rgriffit at ctc.net
Wed May 14 00:20:00 EDT 2003


on 5/13/03 8:18 AM, Shari at gypsyware at earthlink.net wrote:

>> 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.
> 
> The assumption that random(0) would obviously be 0 was made based on
> general principles.  Not on Metatalk itself.  I did not expect to
> have to look up what would seem to be a simple function.
> 
> It was not until the handler failed, and I discovered that random(0)
> consistently produces 1, that I looked it up in the reference docs to
> see if there was an explanation, and some way to fix it to produce 0
> as I intended it to.
> 
> I do not know in general mathematical principles, what result one
> would get from random(0).  But I would expect it to be 0.  My mistake
> for assuming.  (Unless of course, general math principles support my
> theory :-)
> 
> Any math gurus out there know?
> 
> :-)
> 
> Shari C

It is not a result of "general math principles", but "what does the function
actually do?"

There are several little niggly things in programming that violate, say, the
algebraic order of operations.

however, try this out

function randomInteger lowerbound,upperbound
  return random(upperbound-lowerbound+1)-1+lowerbound
end randomInteger

Yes, I am a "math guru". 8*)





More information about the metacard mailing list