>>>>could try
>>>>
>>>>? round( 999 * rand() + 1, 0 )
>>>>
>>>
>>>I have a scheduler type program that was running on multiple PC's for years under FPD 2.6a w/o any errors. After PC's were upgraded the program would generate an error from time to time on one PC only. Further investigation showed that it was a result of RAND() function returning value 1.0. The bottom line, RAND() function can return value 1.0 :)
>>
>>I thought it would be possible, which is why I gave the above suggestion, using round(), rather than int() - to get the full range. If int() were used (with 999 multiplier), then 1000 wouldn't occur with equal probability of other numbers.
>
>By definition, random number generators work in the interval [0,1) - the unpaired parentheses should indicate it can return zero but not one. The reason for this is that most of them use modulo 0xffff or so to achieve a number with a given number of bits. Since implementations may vary, it may get close enough to get rounded to 1000 even without your rounding.
>
>With your additional rounding, you may get
>round( 999 * rand() + 1, 0 )-> round( 999 * 0.99999 + 1, 0 ) -> round( 1000.999, 0 ) -> 1001
Dragan,
I think your maths is a little off there - you're saying 999 * 0.99999 = 999.999
round( 999 * rand() + 1, 0 ) -> round( 999 * 0.9999 + 1, 0 ) -> round( 998.9 + 1, 0 ) -> round( 999.9, 0 ) -> 1000
Len Speed