Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
MOD() - looks like a bug
Message
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
MOD() - looks like a bug
Divers
Thread ID:
00621577
Message ID:
00621577
Vues:
47
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.
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform