|
# Function: getRandom
# Purpose: Generate integer random numbers between a range, and place them in an output array/
# Parameters: in Minimum (integer), in Maximum(integer), out RandomArray (array that holds integers)
# Return Values: Numeric Error codes: 0: OK; -1: error
load("win32api");
public function getRandom(in iMin, in iMax, out aRand[]) {
auto iRange, i;
if (iMin < 0 || iMin > iMax || (iMin + iMax)==0)
return -1;
if (int(iMin) != iMin || int(iMax) != iMax)
return -1;
iRange=(iMax-iMin) + 1;
srand(GetTickCount());
for (i=0; i<iRange; i++)
aRand[i] = int(rand()*iRange) + iMin;
return 0;
}
#When used with the following calling code, random output listings were created.
if (getRandom(1,5,aRnd)==E_OK)
{
buf="";
for (i=0; i<10; i++)
buf = buf & " " aRnd[i];
print(buf);
}
texit;
这是WR中的一个例子,
本人试过了可以运行,
你们可以copy到你的机子上运行.
getRandom()里面的数据可以改变!
大家一起学习 |
|