RANDOM command

Concept Information

Generating random numbers

Generates a set of random numbers.

Syntax

RANDOM NUMBER n <SEED seed_value> MINIMUM min_value MAXIMUM max_value <COLUMNS n> <UNIQUE> <SORTED> <TO {SCREEN|filename}> <APPEND>

Parameters

Name Description
NUMBER n

The size of the set of random numbers to be generated.

A maximum of 32767 numbers can be generated.

SEED seed_value

optional

The value used to initialize the random number generator.

If you specify a seed value, it can be any number. Each unique seed value results in a different set of random numbers. If you respecify the same seed value, the same set of random numbers is generated. Regenerating the same set of random numbers can be required if you need to replicate analysis.

  • Seed value explicitly specify a seed value, and save the value, if you want the option of replicating a particular set of random numbers.
  • No seed value enter a seed value of ‘0’, or leave the seed value blank, if you want Analytics to randomly select a seed value.
MINIMUM min_value The smallest possible number in the set of random numbers. Any valid numeric value or expression is allowed.
MAXIMUM max_value The greatest possible number in the set of random numbers. Any valid numeric value or expression is allowed.
COLUMNS n

optional

The number of columns used to display the set of random numbers.

If you omit COLUMNS, the default is 6 columns.

UNIQUE

optional

Include only unique numbers in the set of random numbers.

If you omit UNIQUE, duplicate values are allowed in the set of random numbers.

Note

Do not specify UNIQUE when the specified size of the set of random numbers exceeds 75 percent of the range between MINIMUM and MAXIMUM. Doing so can result in too many random number selections being discarded.

SORTED

optional

Displays the set of random numbers in ascending order.

If you omit SORTED, the numbers are displayed in the order in which they are randomly selected.

TO SCREEN | filename

optional

The location to send the results of the command to:

  • SCREEN displays the results in the Analytics display area

    Tip

    You can click any linked result value in the display area to drill down to the associated record or records in the source table.

  • filename saves the results to a file

    Specify filename as a quoted string with the appropriate file extension. For example: TO "Output.TXT"

    By default, the file is saved to the folder containing the Analytics project.

    Use either an absolute or relative file path to save the file to a different, existing folder:

    • TO "C:\Output.TXT"
    • TO "Results\Output.TXT"

If you omit TO, the set of random numbers is output to screen.

APPEND

optional

Appends the command output to the end of an existing file instead of overwriting it.

Note

You must ensure that the structure of the command output and the existing file are identical:

  • the same fields
  • the same field order
  • matching fields are the same length
  • matching fields are the same data type

Analytics appends output to an existing file regardless of its structure. If the structure of the output and the existing file do not match, jumbled, missing, or inaccurate data can result.

Examples

Generate a text file with 100 random numbers

You want to pull 100 hard copy files at random from a set of files with numbering that ranges from 10,000 to 20,000.

You can use the RANDOM command to generate a text file with 100 random numbers between 10,000 and 20,000. You then pull the hard copy files that match the random numbers. The numbers are arranged in 10 columns, are unique, and are sorted in ascending order:

RANDOM NUMBER 100 SEED 45387 MINIMUM 10000 MAXIMUM 20000 COLUMNS 10 UNIQUE SORTED TO "Random_Numbers.txt"

Remarks

For more information about how this command works, see Generating random numbers.

Random number algorithm

The RANDOM command uses the default Analytics random number algorithm. Unlike the SAMPLE command, the RANDOM command does not have the option of using the Mersenne-Twister random number algorithm.