|
|
|
|
| 4D v11 SQL Road Show |
| 4D, Inc. has announced the 4D v11 SQL Road Show. The tour includes stops in seven U.S. cities. The morning session is free, followed by an afternoon training session priced at $299 ($199 for Partners).
8:45 AM PST |
|
| Minneapolis Area 4D Users Group Meeting on May 19th |
| The next Minneapolis area 4D users group meeting will be held on Monday, May 19th at 7 PM.
12 May 2008 |
|
|
Submit Future News Archive  |
|
|
 |
|
|
| Getting a Random Selection of Records |
Submitted by Brian Campbell, PetData Inc.
There are several reasons that you may want to get a random selection of records from a particular table. The following method does just that. Note that it uses another method number_RandomLong, published previously.
There are two different 'methods' for getting the selection. Which one you use will depend on your application. The 'Array' method is better for larger result sets, but may stall somewhat with very large starting selections. The 'Sets' method is not affected by the size of the source selection, but has a greater overhead and slows as your result set size increases. Do some testing and determine which works best for your purposes.
` GetRandomSelection (SourceTable;RecordCountToGet) ` ` Makes a random selection of records in the source table ` Uses the current selection as a starting point ` If starting selection is same or less than record count to get, the current ` selection of the table is not changed ` ` $1 - $sourceTable_ptr - pointer to the table to work on ` $2 - $recCountToGet - longint - total number of records in resulting selection ` $0 - <none>
C_POINTER($1;$sourceTable_ptr) C_LONGINT($2;$recCountToGet) $sourceTable_ptr:=$1 $recCountToGet:=$2
C_BOOLEAN($useArrays) $useArrays:=True ` You may wish to establish some sort of criteria to determine which method ` is used, such as the specific table or the size of the source/result selections. ` This could also be added as a third optional parameter with a default.
C_LONGINT($startRecordCount) $startRecordCount:=Records in selection($sourceTable_ptr->)
If ($startRecordCount > $recCountToGet) ` Make sure we have enough source records If ($useArrays) ` This method uses arrays and record ids ` Setup source and result arrays ARRAY LONGINT($allRecordIDs_aL;0) ` Source LONGINT ARRAY FROM SELECTION($sourceTable_ptr->;$allRecordIDs_aL) ARRAY LONGINT($resultRecIDs_aL;$recCountToGet) ` Result C_BOOLEAN($foundUnique) C_LONGINT($rec;$thisRecID;$resultIndex;$randomIndex) For ($rec;1;$recCountToGet) $foundUnique:=False ` Set true when we know we have a unique rec ID Repeat ` Pick a random rec ID $randomIndex:=number_RandomLong (1;$startRecordCount) $thisRecID:=$allRecordIDs_aL{$randomIndex} ` Check for uniqueness If ((Find in array($resultRecIDs_aL;$thisRecID))=-1) ` Not yet in result array $foundUnique:=True End if Until ($foundUnique) $resultRecIDs_aL{$rec}:=$thisRecID ` Add this rec ID to the result array End for ` Change the selection using the result array of rec IDs CREATE SELECTION FROM ARRAY($sourceTable_ptr->;$resultRecIDs_aL) Else ` This method simply builds a set with goto selected record C_TEXT($randomSetName) $randomSetName:="RandomResultSet" CREATE EMPTY SET($sourceTable_ptr->;$randomSetName) Repeat ` Goto a random record number in the selection GOTO SELECTED RECORD($sourceTable_ptr->;number_RandomLong (1; $startRecordCount)) ` Add this record to the set ADD TO SET($sourceTable_ptr->;$randomSetName) Until (Records in set($randomSetName)=$recCountToGet) ` Change the selection and clear the set USE SET($randomSetName) CLEAR SET($randomSetName) End if ` which method to use End if `(Records in selection($sourceTable_ptr->) > $recCountToGet) |
|
Submit a Tip Archive  |
|
|
 |
|
|
|
| 10 Big Myths about Copyright |
We recently ran across an interesting article we thought we'd share with you. Brad Templeton's 10 Big Myths about Copyright does a good job of explaining some of the gray areas about copyright law. |
|
Suggest a Spotlight
|
|
|
 |
|