Select random records by two conditions

S

Slim Slender

I need help. I have several hundred records representing transactions
within a particular month. I want to select two random samples for
each client for each day of the month. In other words, select random
samples based on two conditions or criteria. One problem I have
encountered is when there are no examples for a client for a
particular day I get an error. I think the pseudo-code or algorithm
might go a little something like this . . . swing it boys.
Create a collection of dates
Create a collection of names
Create an array to hold records
For the first date
For the first name
For records 1 to infinity
Select a random record
Test for duplication
Add to array
Loop
Write array of records to another sheet
Next name
Next date
I already have some chunks of the code but it doesn’t work as a whole
because I think I have the order of execution wrong. Any help would be
appreciated.
 
A

Auric__

Slim said:
I need help. I have several hundred records representing transactions
within a particular month. I want to select two random samples for
each client for each day of the month. In other words, select random
samples based on two conditions or criteria.

Give some examples of the records' format(s).
One problem I have
encountered is when there are no examples for a client for a
particular day I get an error. I think the pseudo-code or algorithm
might go a little something like this . . . swing it boys.
Create a collection of dates
Create a collection of names
Create an array to hold records
For the first date
For the first name
For records 1 to infinity
Select a random record
Test for duplication
Add to array
Loop
Write array of records to another sheet
Next name
Next date

I would think it would be more like this (untested air code):

for each c in clients
for each d in dates
r_c_d = [set of records where date is d and client is c]
r_1 = int(rnd * r_c_d.count) + 1
remove r_1 from r_c_d
r_2 = int(rnd * r_c_d.count) + 1
next d
next c
I already have some chunks of the code but it doesn’t work as a whole
because I think I have the order of execution wrong. Any help would be
appreciated.

Maybe my air code will poke some ideas in your direction.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top