Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Random number generation
Message
De
06/05/2003 09:56:38
 
 
À
06/05/2003 09:50:39
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00785329
Message ID:
00785351
Vues:
17
I suppose that may simplify the code a little. How about the randomness of the numbers that are returned, do you believe this to be as random as it can be? The help file indicates calling RAND 1st with a -1 to achieve the most random result.

Jeff


>If you just want to get ca. 5% of the population, you can make it a little simpler. There is no need to multiply rand() with any constant; just compare if rand() < 0.05 for all employees:
>
>
>rand(-1)
>scan
>  if rand() < 0.05 && 5%
>    * process this employee
>  endif
>endscan
>
>
>HTH,
>
>Hilmar.
>
>
>>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
>
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform