Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
RAND() value range
Message
From
04/12/1998 19:09:40
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00164229
Message ID:
00164361
Views:
20
>I don't know about a definition, but testing that seems more fun than working on a Friday afternoon.
>
>>I always thought that the allowable return value range included 0, but did not >include 1
>
>after generating 100 million random numbers (initializing with rand(-1))
> ?minvalue=0 was .T.
> ?maxvalue=1 was .F.
>
>I also ran smaller sets of 10 million a couple of times and usually got a 0 (which statistically shouldn't have happened unless "=" rounds) but never a 1. Rand() seems to round to 15 decimal places, so statistically 100 million tries doesn't prove anything. To be 99% I'd need to run 10^18 tries, and I ain't gonna live that long.

...........
Dan,
It's good to see your results matching with the rule that I remembered even if the number of 0's you got is a little suspicious.

I’ve found the source of my initial understanding in one of my old dBASE books (anybody remember dBASE?). It says that RAND() returns a number from 0 to 0.999999... INCLUSIVE.

This is of course what we would hope it would do. That way the result can be in any 1 of 10 EQUALLY sized packages

0.0 to 0.09999...
0.1 to 0.19999...
0.2 to 0.29999...
...
...
0.9 to 0.99999...

As long as VFP has kept the same philosophy, we won’t have to deal with the occational 1.0 that would fall outside of our 10 equal probability ranges.

Thanks to all that actually put the question to the test.

Bob
Previous
Reply
Map
View

Click here to load this message in the networking platform