Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Random selections
Message
 
 
To
16/02/2000 18:53:25
Erin Eby
Mission Critical Software
Gainesville, Florida, United States
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00333179
Message ID:
00333322
Views:
15
>Hi, i am wondering...i am reletively new to foxpro and was wondering if there was a way to put a table of 50 different records into groups of 2. example: i have 50 people and i want to divide them up into 25 groups of 2, where the group of 2 is generated randomly. so in essence what i'm looking for is a command that will generate random numbers, creating tables where the same 2 people are not paired up every time.

Here's a simple routine that I used for something similiar. You will probably want to modify to handle varying record lengths, odd record counts, etc.
dimension shuffle(50)
dimension group1(25), group2(25)
*Create array of non-repeating values
for lp=1 to 50
    shuffle(lp)=lp
next
*Randomize the order
=Rand(-1)
for lp = 1 to 50
    swaptoloc = INT(50 * RAND() + 1)
    swaptmp = shuffle(lp)
    shuffle(lp) = shuffle(swaptoloc)
    shuffle(swaptoloc) = swaptmp
next
*Create groups by seperating even/odd on loop counter
select YourDataBase
l1Idx = 1
l2Idx = 1
for lp = 1 to 50
    goto shuffle(lp)
    if mod(lp,2) = 0
       group1(l1Idx) = YourDataBaseFieldNameGoesHere
       l1Idx=l1Idx+1
    else
       group2(l2Idx) = YourDataBaseFieldNameGoesHere
       l2Idx=l2Idx+1
    endif
next
HTH
Michael McLain
Previous
Reply
Map
View

Click here to load this message in the networking platform