Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Random Selection of Records

Status
Not open for further replies.

oshlonger

IS-IT--Management
Oct 31, 2002
76
US
I have a basic report that lists out 13,200 Ids. There is no grouping or any other type of formating on these records. I would like to select a random sample of about 100 records.

I'm trying to create a formula that grabs every 132nd Id. I'm not sure if I'm going about this the correct way. Could someone please assist me?
 
Create a formula to be used as a group that contains:

Rnd()

Sort the report by the formula and create a record selection formula on a group that has

recordnumber <= 100

-k
 
Most databases have a random number generator. Using this assures better truely random selection without having to bring back all the records:

example:

Parameter ?PercenttoUse

enter this as a decimal ie 20% would be .2


SQL expression %Random:

Rand()

Selection formula

{?PercenttpUse} <= {%Random}


Lisa
 
Thanks. I did not know there was a Random function (Rnd). I was able to figure it out, not so easily but it worked. Here is how I did it:

I created a formula @counter and placed it in the details
[tt]WhilePrintingRecords;
NumberVar Counter := Counter +1;[/tt]

Then I created another formula @random and placed it in the details
[tt]{@counter} Mod 132[/tt]

Then I formatted my details section to suppress any record where @random <> 0

I know its a bunch more steps but I was happy to get where I was going.

Thanks for the help
 
That works well for a subset.. but probably not a truely random set. If you run the report twice, you will probably get the same records. You will need to incorporate either the SQL or crystal random to get a truely random sample.

Lisa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top