Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Rand()
Message
 
To
09/09/2005 10:38:53
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Re: Rand()
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01048125
Message ID:
01048132
Views:
18
This may help:
Procedure yRand
*Generate a random integer in particular range
LPARAMETERS pnmin, pnmax
LOCAL ln
ln=RAND(-1)
DO CASE 
CASE TYPE("pnmin")#"N" AND TYPE("pnmax")#"N"
	RETURN RAND()
CASE TYPE("pnmin")="N" AND TYPE("pnmax")="N"
	RETURN INT(ABS(pnmax-pnmin)*RAND())+MIN(pnmin,pnmax)
CASE TYPE("pnmin")="N"  && return numbers between 0 and pnmin
	RETURN INT(pnmin*RAND())
otherwise  && return numbers between 0 and pnmax
	RETURN INT(pnmax*RAND())
ENDCASE
>I'm searching for a code snippet that will create random numbers within a defined range. I've been tinkering with rand() but it seems to always come up with the same random number based on what is in the braces. That's great if you only want one random number, but I need to be able to set the number of numbers and the range of those numbers.
Previous
Reply
Map
View

Click here to load this message in the networking platform