# Thread: Randomly selecting itms from a list box...

1. ## Randomly selecting itms from a list box...

User RAFAEL ROSA (***_11@yahoo.com.nospam) posted:

Does anyone have an example of how WR 6.02 can
randomly select an item from a list box in a loop? Any

Robert

__________________________________________________

2. ## Re: Randomly selecting itms from a list box...

This is WR 7.0 but should work in 6.02

This code is ugly and un-tested...
You should have No duplications using this function. Each number will only be used once...it's magic

# This function will populate an array with values in the range "iMin" thru "iMax".
# if iMin=1 and iMax=15 you should get an Array of ArrayX[0] thru ArrayX[14]
public function getRandom(in iMin, in iMax, out aRand[])
{
auto iRange, loopX, i, x, Found, rc1, randomX, randomY;

if (iMin < 0 | | iMin > iMax | | (iMin + iMax)==0)
return -1;

if (int(iMin) != iMin | | int(iMax) != iMax)
return -1;

srand(GetTickCount());
iRange = (iMax - iMin) + 1;
i = 0;
loopX = iMax - 1;
while ( i < loopX )
{
randomX = int(rand() * iRange) + iMin;
if ( length(aRand[0]) < 1 )
{
aRand[0] = randomX;
}

x = 0;
Found = 0;
for (x in aRand)
{
randomY = aRand[x];
if (randomY == randomX)
Found = 1;
}
if (Found != 1)
{
i++;
aRand[i] = randomX;
}
}
return 0;
}

reload ( "C:\\WinRunner\\lib\\win32api", 1, 1 );

rc1 = getRandom(1, 15, ArrayX);

for (xx in ArrayX)
countX++;

# ArrayX should contain numbers 1 to 15 with No duplications.

# if you get the data from the table using "ddt_val_by_row" you can use the numbers in ArrayX. "countX" contains the number of elements in ArrayX.
ArrayX[0] thru ArrayX[14]

------------------

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.