Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
MOD() - looks like a bug
Message
From
20/02/2002 12:30:23
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00621577
Message ID:
00622663
Views:
31
>>What's wrong with mod() returning fractions?
>>Cetin
>
>It's that if you run say CertainRand(2,8) several times the chances are that on a certain run the function will indicate that MOD() returns, for example, 5.25 while arguments that it had were MOD(1145880599506199.0000,6). If you take this statement and execute it in the command window it returns the correct whole number. On the contrary, from within the function the result is a fraction.
>Regards.
>Kamil.

I can't reproduce. I'd go with a simplier routine :
rand(-1)
create cursor randvals (rnd b(2))
for ix=1 to 1000
   insert into randvals values (round(CertainRand(2,8),0))
endfor
locate
brow
* 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
otherwise
	return rand()*(nUpperlimit-nLowerLimit)+nLowerLimit
ENDCASE 
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform