General information
Category:
Coding, syntax & commands
>>>>>>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
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only