Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Need an efficient random generation routine
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00114512
Message ID:
00114537
Vues:
18
Gerry,
n = 10
select rand() as rnd, employee.*;
   from employee ;
   into cursor testem ;
   where .... ;
   top N
if ( _tally > N )
   delete for recno("testem") > N
endif
It's possible to get more than N records in case of ties of the random number.

>I've been tasked with putting together a routine which will grab a certain number of names from our employee tables for our random drug testing.
>
>I know FPW/VFP has the RAND() function but I need to see if someone has a function which, more or less, produces more randomness.
>
>What I'd like to do is:
> a. Use a SQL SELECT to create a cursor with all active employees from a particular paygroup (for us these indicate at which state/site the employee works) - I now know the range of numbers I can pick from - the number of employees in my 'pool'.
> b. Based on the _TALLY of the above SELECT, I can create a random list of 10 record #'s from the cursor.
> c. I can put those records into another cursor and grab the 'lucky' employees' names for our HR director
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform