Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Random numbers - the most efficient way
Message
 
 
To
08/09/2004 01:17:59
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00939849
Message ID:
00940286
Views:
19
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform