Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Random Number
Message
From
26/11/2001 14:23:17
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
 
To
26/11/2001 12:03:27
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Miscellaneous
Thread ID:
00585489
Message ID:
00585914
Views:
36
>>>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

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform