Ph: 800-848-2576
Fax: 360-654-8170
Contact Us
Selecting Data at Random
This exercise uses variables in the selection window to randomly select every nth record.  This selection was originally developed for a customer who was performing a random audit and wanted to be able to select every third record.  In this exercise we define variables to select records based on an established interval, as every third record.  In order to get a random sampling of our data it uses logic we call 'Remainder' logic and we use it to satisfy many of our customer requests.

In the Selection Variables window, create the following:

 Name

 Type

 Len

 Initial Value

 CNT

 Num

 6

 

 INT

 Num

 6

 ?INTERVAL


When finished, click Close. In the Selection Computations... window, enter the following information:

 Name

 Expression

 Condition

 CNT

 CNT + 1

 



When finished, click OK. In the Selection Criteria window, enter the following information:
    (CNT / INT * INT) = CNT
Each time the selection is executed, Visimage for Windows will select the nth record, where n is the INTERVAL supplied by the user.  The table below assumes an interval of every 3 records:

 Rec #

 CNT

 (CNT / 3 * 3)

 Select Record ?

 1

 1

 1 /  3 * 3 = 0

 No

 2

 2

 2 /  3 * 3 = 0

 No

 3

 3

 3 /  3 * 3 = 3

 Yes

 4

 4

 4 /  3 * 3 = 3

 No

 5

 5

 5 /  3 * 3 = 3

 No

 6

 6

 6 /  3 * 3 = 6

 Yes

 7

 7

 7 /  3 * 3 = 6

 No

 8

 8

 8 /  3 * 3 = 6

 No

 9

 9

 9 /  3 * 3 = 9

 Yes

 10

 10

 10 /  3 * 3 = 9

 No

 11

 11

 11 /  3 * 3 = 9

 No

 12

 12

 12 /  3 * 3 = 12

 Yes



The reason that this selection works is because AskPlus does integer arithmetic and, by default, truncates the result on division.  This means that (1 / 3) and (2 / 3) both equal zero.  Zero multiplied by 3 is zero and, therefore, the first two records are not selected.  For record 3, the result of (3 / 3) is 1 and (1 * 3) is 3, so the third record is selected.  Records 4 and 5 do not qualify, and the next selected record is number 6.

To illustrate another example, the table below assumes an interval of every 4 records:

 Rec #

 CNT

 (CNT / 3 * 3)

 Select Record ?

 1

 1

 1 /  4 * 4 = 0

 No

 2

 2

 2 /  4 * 4 = 0

 No

 3

 3

 3 /  4 * 4 = 0

 No

 4

 4

 4 /  4 * 4 = 4

 Yes

 5

 5

 5 /  4 * 4 = 4

 No

 6

 6

 6 /  4 * 4 = 4

 No

 7

 7

 7 /  4 * 4 = 4

 No

 8

 8

 8 /  4 * 4 = 8

 Yes

Send questions & comments regarding the Vital Soft site to:  webmaster@vital-soft.com
Copyright © 1998-2012, Vital Soft, Inc.