Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Random numbers - the most efficient way
Message
 
 
À
08/09/2004 01:17:59
Al Doman (En ligne)
M3 Enterprises Inc.
North Vancouver, Colombie Britannique, Canada
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00939849
Message ID:
00940286
Vues:
18
This message has been marked as a message which has helped to the initial question of the thread.
Al,

>I agree that this technique is elegant. However, Nadya asks for "efficient" in the thread title. As a guess, I'd say this technique isn't that efficient. For example, if you are trying to pull 40 random records out of a million, this technique means a million records will be pulled over the wire, sorted, then the top 40 sliced off the top. Doing 40 random GOTOs in the same million-record table may be more efficient.

Most certainly if you have a huge table or slow network based file and only want a few records it's much more time efficient to do something like:
rand(-1)
lnRecs = reccount( "TheSampledTable" )
select * ;
   from TheSampledTable ;
   into cursor TheSample readwrite ;
   where 1=2

do while reccount( "TheSample" ) < lnSampleSize
   select TheSampledTable
   goto int( lnRecs * rand() ) + 1
   if ( ! deleted() )
      scatter name oData memo
      select TheSample
      append blank
      gather name oData memo
   endif
enddo
df (was a 10 time MVP)

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

Click here to load this message in the networking platform