EdTech wrote:


> I have the following script to generate a random number between upper
> and lower limits. 

[snip]


> on generateMCH
>   global MCH, glower, gupper
>   put empty into MCH
>   repeat until MCH >glower
>     put  random(gupper) into MCH -- this is the line that 
>                                     fails, I think
> 
>   end repeat
>   put MCH/10 into MCH
>   put MCH into line 5 cd field "RBCresults"
> end generateMCH


I can't see anywhere you can get a divide by zero error in this script,
unless there is a bug in the random function. But I suspect there is an
easier way to do this:

function myRandom lower,upper
   return trunc((random(30000)-1)/30000 * (upper - lower)) + lower
   -- returns a whole number R,  lower <= R < upper
end myRandom

30000 isn't a particularly special number, I just pick it because it is
large, thus giving myRandom a fairly high resolution.

If you need to include both bounds in the range of values, use
random(30000) instead of random(30000)-1.

-- 
Steven D'Aprano

==========================================
M.B. Sales Pty Ltd    Ph:  +61 3 9460-5244
A.C.N. 005-964-796    Fax: +61 3 9462-1161

Archives: http://www.mail-archive.com/metacard%40lists.best.com/
Info: http://www.xworlds.com/metacard/mailinglist.htm
Please send bug reports to <[EMAIL PROTECTED]>, not this list.

Reply via email to