Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
MOD() - looks like a bug
Message
From
18/02/2002 12:40:06
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
MOD() - looks like a bug
Miscellaneous
Thread ID:
00621577
Message ID:
00621577
Views:
48
Hello All.
I have VFP7, wrote a short function for generating pseudo-random values within the specified range. What i’ve noticed is that MOD() sometimes returns fractions, not whole numbers. Run the code below a dozen times and you will see that the MOD(nResult,nScissors) sometimes returns fractions. Try something simple – CertainRand(2,8)
Best wishes.
Kamil.
* random values
* E.g. between -2147483647 and +2147483647 (int datatype range)
function CertainRand
lParameter nLowerLimit, nUpperLimit
DO CASE 
CASE nLowerLimit>nUpperLimit
	RETURN null
CASE nLowerLimit=nUpperLimit
	RETURN nLowerLimit
ENDCASE 
local nResult, nScissors
?
?
nScissors=nUpperLimit-nLowerLimit
?nScissors
nResult=rand(-1)*10**16
DO WHILE nResult<1*10**15
	nResult=rand()*10**16
ENDDO 
?nResult
nResult=MOD(nResult,nScissors)		&& nUpperLimit is never reached
?nResult
IF nResult=0
	nResult=IIF(rand()*10**15<5*10**14,0,nScissors)	&& to reach 	nUpperLimit
endif
return nLowerLimit+nResult
A moment of silence is our cosmic reset button.
Next
Reply
Map
View

Click here to load this message in the networking platform