Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Selecting 10 records randomly
Message
From
04/01/1998 00:07:56
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00069291
Message ID:
00069298
Views:
35
>>>>What would be the best technique to select 10 records randomly from a table?
>>>Michel, do you mean by RECNO() ?
>>
>>I have a set of 250 records. Depending on the SQL, I may have a total of 135 records approx. for the SQL result set. From those, I would like to select 10 records randomly.
>>
>>I tried various techniques but I don't like them. I figured their must be something better.
>
>I always used just basic
>=rand(-1)
>x=rand()
>and then make a value from X some way, corresponding the necessary range.

Yes, but the random need to be taken from existing records.

Let suppose I have 135 records in my cursor. I can GO BOTTOM to have my random value. In this case, the value is 135. So, I need to execute the random 10 times and to GO to the cursor record RECNO() from the random value to get my unique key so I can construct my final SQL. I also need to make sure I don't choose the same record twice.

When I have my 10 values, I can then to the final SQL with a WHERE INLIST(uniquekey,value1,value2,value3...).

This is what I was wondering is something better can be done.
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform