Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Surprise: RAND() is an integer
Message
 
 
To
12/01/2006 04:03:09
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 9
Miscellaneous
Thread ID:
01085963
Message ID:
01086166
Views:
13
Fabio,

Internally a 32bit unsigned integer is used. Most every popular pseudorandom number generator for the last 40 years has used them. Given a decent (large prime) seed value it will in theory be able to return 2^32 distinct values. The docs state the return value is between 0 and 1 (being somewhat moot about either endpoint inclusion). The fact that exactly 1.00000000000 isn't going to come out of this function does nothing to reduce its functionality. It actually enhances our ability to more easily convert the number into an integer range of our choosing.

FWIW a 10,000,000 sampling of possible 4,294,967,295 values isn't adequate counterproof.

And they are called pseudorandom number generators for the main reason that the algorithms can not generate perfectly random numbers.

>I don't know if it were known,
>but RAND() it doesn't produce a full double float [0-1) value but on the contrary
>it is an uint normalized to 1 with uint/2^32.
>
>Then, the values that RAND() can return are:
>
>0 .. (1 - 2^-32) with a 2^-32 step
>
>and certainly RAND() cannot return 1.
>
>This reduces it's pseudocausal dynamic and a lot of other statistic characteristics are different.
>
>For example,
>if a casual order is produced with RAND() the index uses 8 bytes for key,
>with CAST(BITAND(RAND()*2^32,-1) AS I) only 4 bytes are enough
>without to lose information.
>
>
>RAND(-1)
>FOR K=1 TO 10000000
>	IF RAND()* 2^32 % 1 = 0	&& is a LONG
>		LOOP
>	ENDIF
>	MESSAGEBOX("rule violation",16)
>	EXIT
>NEXT
>
>Fabio
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Previous
Reply
Map
View

Click here to load this message in the networking platform