Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Random number generation
Message
De
06/05/2003 09:35:46
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Random number generation
Divers
Thread ID:
00785329
Message ID:
00785329
Vues:
43
Hello all,

I have a program that selects employees for random drug testing. I would like to verify that my code produces the most random number possible. I just pasted the code below, any comments are appreciated.


Thanks, Jeff

_________________________________________________________________________

lparameters lcPlantNo

* get only active employee #'s into the temporary
* table
select prempl,first,last ;
from prempl01 where left(prempl,1) = lcPlantNo ;
and status = "A" ;
union all ;
select prempl,first,last ;
from prempl02 where left(prempl,1) = lcPlantNo ;
and status = "A" ;
into cursor tmpEmpl

select tmpEmpl

nRecs = reccount()
* the number of tests to perform is 5% of
* the total population for this plant
nNumTests = round(nRecs * .05,0)
nTested=0
* initialize the seed value
nEmplNo = rand(-1)
do while nTested < nNumTests

* get the random employee number
nEmplNo = int(nRecs * rand() + 1)
* random sort for printout
nRandSort = rand()*100

if nEmplNo < 1 or nEmplNo > nRecs
loop
endif

* save the employee to the temp file
goto nEmplNo in tmpEmpl
select testnumbers
seek tmpEmpl.prempl
if !found()
* employee not already included in this test
nTested = nTested + 1
append blank
replace empid with tmpEmpl.prempl
replace last with tmpEmpl.last
replace first with tmpEmpl.first
replace randsort with nRandSort
endif
enddo

use in tmpEmpl
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform