Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Selecting 10 records randomly
Message
From
04/01/1998 01:38:05
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00069291
Message ID:
00069313
Views:
38
>>>>>>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.
>
>I believe in simple things... :)
>
>n=reccount()
>=rand(-1)
>x=rand()
>nextnumber = int(n*x)

You're off by one here, don't you?

>then save the number into array[10]
>get nextnumber, check if it is already in array, if not save it there... 10 times in a row (or more :)
>?
>:)
Previous
Reply
Map
View

Click here to load this message in the networking platform