Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Random number between -1 and 1
Message
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01387218
Message ID:
01387321
Views:
40
Joe

This will generate floating point values between -1.0 < = x < 1.0
function UniformRandomBetweenNegativeOneAndOne()
return -1.0 + rand() * 2.0
If you just want the three integer values -1, 0 and 1
function RandomIntegerBetweenNegativeOneAndOne()
local lnRand
lnRand = rand()
return iif( lnRand <= 1.0 / 3.0, -1, iif( lnRand <= 2.0 / 3.0, 0, 1 ) )
>I've used the example from help on how to generate random numbers. Now I need a random number between -1 and 1 (integer -1,0,1) and cannot figure out how to modify the example to give negative and positive numbers. Any tips?
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