Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Selecting a Winner
Message
From
15/06/1999 12:59:59
 
 
To
14/06/1999 19:53:28
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00226460
Message ID:
00230051
Views:
31
Hmmm... WHen I needed to do a random selection, I found a pretty good spread by assigning each record a random number and then sorting on that, assigning a second random number, sorting on that, reassigning the first random number, and then looping this process 40 or 50 times. I got an even distribution by the time the program was done.

>You are right and wrong in the same time. :) I cannot give a predictable algorithm.
>
>Here's why I say it is not correctly random:
>The SELECT may extract more than one record with the same random key. If you take the first record (or according with any other rule) from the resulted cursor, than this second choice is not random. Let's say that SELECT returns records in the phisycal order when no other rule is in effect. This would mean that the records at the beginning of the table have more chances to be selected as the final winner. This says that the chance is not the same for all records, thus, my statement.
>
>If you don't believe me, you can make tests with rand()*2 (it doesn't reduce the random character of the alghorithm). I bet it will balance to the records in the first half of the table.
>
>I would say that if the number of records is much less than 1000000, the random choice is almost correct and it doesn't matter.
>
>Vlad
>
>>I disagree. Random does not necessarily mean unique. If you want to make sure you do not select the same person, then store the previous winners in a table for comparison. However, unless you can show me a predictable algorithm used by SELECT TOP 1 RAND()*1000000 etc. then it is random.
>>
>>George
--Todd Sherman
-Wake Up! Smell the Coffee!
Previous
Reply
Map
View

Click here to load this message in the networking platform