Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Random numbers - the most efficient way
Message
 
 
À
09/09/2004 01:26:28
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00939849
Message ID:
00940512
Vues:
20
Al,

If the table was already randomized, which would take a distinct process to randomly reorder the records, then yes, you could start at a random record and pull a sequential set of rows. But since every databases I've worked with adds new records to the end of the table (or into recovered deleted space in the case of a SQL server) in the order of insertion, the table will have a "time dependency" between the data rows.

If you weigh the amount of work it takes to randomwly reorg the table vs the amount of work to

select top N PK, rand() ;
from ....

I'm sure you'll see just doing the TOP N select and then joining the sample PK back to the original table to pull the final dataset would be faster in general.

Randomness is near and dear to my heart, I did a couple of years of research work using Monte Carlo simulation techniques to study radiation transport of neutrons and gamma rays through reactor vessels and radiation sheidling. A lot like ray tracing that is used now to create computer generated images in Pixar films.

>Hmm... my cellphone call example may not be a good illustration of the idea; you could well get only people who call around midnight, and none around noon. Clearly you have to remove any record-to-record dependencies.
>
>But, suppose you have a cursor with a million random integer values, not related to each other. If you want 40 random values, taking 40 sequential records is just as good as taking 40 at random.
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