
This file has information and documentation for using the rnm.exe program
to generate random numbers.  The program uses a reliable pseudorandom 
algorithm to generate random numbers with various options for research. 
The program can be downloaded and used as needed.  I consider it public 
domain.

The rnm.exe program was written several years ago for DOS computers.  It 
works as a DOS program under Windows.

Download the program by clicking on the download link on the web site.  
Choose Save file.  The easiest way to handle this is to make a folder for
random numbers and put the program there, as well as the data files that
are made with the program.

After the program is downloaded to your local computer, the simplest way 
to start it is to double click on it from a Windows directory listing 
(e.g., Windows Explorer).  When the program starts, it gives a black DOS
screen with input lines at the top.


The input lines for the program are:

RNM>No. Possible Outcomes (1/P)  (0-Stop)>
  Enter the number outcomes, targets, or conditions that are being randomly
  selected.  For example, if a target is being selected from 6 possible 
  targets, enter 6.  Random numbers from 1 to 6 would be generated.  If a 
  target pool is being selected from 100 possible target pools, enter 
  100.  If a subset of subjects is being randomly selected for further 
  evaluation from a large study of 1000 subjects, enter 1000.  The largest 
  number that can be used is about 32000. If 0 (zero) is entered, the 
  program stops.
  
RNM>Trials per Run or Set>
  In some cases the random numbers logically fall into groups such as 25 
  trials for each subject.  These groups may also be called sets, runs, or 
  blocks. The term set is used in these instructions. Enter the number of 
  random numbers that are wanted for a set.  In other situations it will 
  not be meaningful to generate the numbers in groups and 1 will be entered.  
  In some cases, a larger number will be used for convenience in processing 
  the numbers.  The maximum number per set is 200.  If 0 (zero) is entered, 
  the program stops.
  
RNM>With Replacement (Y or N) [Y]>
  Enter Y if the random numbers are to be generated with replacement (i.e.,
  if a number is selected, it can be selected again in the set).  Enter
  N if the numbers are generated without replacement so that a number can only
  occur a limited number of times in a set, or a blanced outcome is 
  wanted (such as when randomizing subjects to experimental conditions).

  Random numbers generated without replacement will be generated and balanced
  by set.  For example, to simulate playing cards, have No. of Outcomes=52 
  and 52 trials in a set.  Then generate the random numbers without 
  replacement.

  With replacement (Y) is appropriate in most cases for generating random
  targets or stimuli of some kind.
  
RNM>Order in Set Randomized (Y or N) [N]>
  This line only comes up if you are selecting a subset of numbers from a 
  larger range of numbers, such as randomly selecting a subset of subjects 
  from a large pool (e.g., randomly selecting 30 subjects from a pool of
  200 subjects).  This occurs when the numbers are generated without
  replacement and the number of possible outcomes is larger than the number
  in the set.  By default the numbers will be generated in ascending
  order (e.g., 3,7, 25, etc).  If this is set to Y, then the order of the
  selected numbers is randomized (which should rarely be needed).  
  
RNM>Number of Runs or Sets>
  Enter the number of sets that are needed.  The program stops if 0 (zero) 
  is entered.
  
RNM>Compressed Output (Y or N) [N]>
  This line only comes up if there are more than 25 sets.  If Y is selected, 
  the output is compressed for ease of reading with a computer and to save 
  space.  Also, the header information for the batch on random numbers is not 
  put in the file.  
  
  The normal output has information about the batch of random numbers, 
  including date and entry numbers for the algorithm, and also spaces the
  output for ease of manual processing.  An example is given below.  This
  output is not used if compressed output is selected.
  
RNM>Output to [con]>
  Enter the name of the output file.  Since this is a DOS program, the file
  name can be no more than 8 characters for the main part and 3 characters 
  for the extension after the period.  The output is a simple ascii text file 
  and is usually best handled in Windows with an extension of .txt.  So a 
  good name would be something like: group1.txt.  The file can be read with 
  Notepad or another text editor (or word processor).  Note the file can be 
  renamed to a longer name after it is created. 
  
  The DOS instructions for writing to a different folder can also be used
  (including 8 character limit) but it is easiest to just run the program
  from the folder where you want the output file.
  
  The default output is con, which is to the terminal display.  However, 
  when the program is run by double clicking on it from Windows, it displays
  the output on the screen just briefly as it returns to Windows.  To see the
  output on the screen, the program needs to be run from the DOS prompt -- 
  which can be started under Windows accessories.
  
  The easiest way to use the program is to run it from the folder where you 
  want the output, name the output file with a .txt extension, and then look
  at the output file with Notepad.
  
  
------------------------------------------------------------------------------

Here are some example input commands.

Example case 1: You have 30 different target pools with 6 targets in each pool.
For an experiment with 50 subjects, you need to select for each subject a
target pool, a random order for the targets in the pool, and a target for
the trial.  These are done with separate runs of the program.


To select one of 30 target pools for 50 subjects:
 RNM>No. Possible Outcomes (1/P) (0-Stop)>30
 RNM>Trials per Run or Set>1
 RNM>With Replacement (Y or N) [Y]>Y
 RNM>Number of Runs or Sets>50
 RNM>Compressed Output (Y or N) [N]>N
 RNM>Output to [con]>tpool.txt

 Note, this could also be done with 1 set of 50 trials.


To select a random order for presentation of the target to a subject:
 RNM>No. Possible Outcomes (1/P) (0-Stop)>6
 RNM>Trials per Run or Set>6
 RNM>With Replacement (Y or N) [Y]>N
 RNM>Number of Runs or Sets>50
 RNM>Compressed Output (Y or N) [N]>N
 RNM>Output to [con]>torder.txt


To select a random target for each of the 50 subjects:
 RNM>No. Possible Outcomes (1/P) (0-Stop)>6
 RNM>Trials per Run or Set>1
 RNM>With Replacement (Y or N) [Y]>Y
 RNM>Number of Runs or Sets>50
 RNM>Compressed Output (Y or N) [N]>N
 RNM>Output to [con]>targets.txt


Example case 2: You collected data on 350 subjects as part of a large 
study and now you want to randomly select 20 subjects for a quality 
control review or for further evaluation.  The input would be:

 RNM>No. Possible Outcomes (1/P) (0-Stop)>350
 RNM>Trials per Run or Set>20
 RNM>With Replacement (Y or N) [Y]>N
 RNM>Order in Set Randomized (Y or N) [N]>N
 RNM>Number of Runs or Sets>1
 RNM>Output to [con]>subset.txt



------------------------------------------------------------------------------

Here are some example outputs.


Below is an example for randomly ordering 6 conditions for 10 subjects.


        ****************** RNM Version (6D) ********************
                    Run at 13:54:39 on  03-30-2005

          No. Outcomes (1/P) = 6          Replacement = N
          No. Trials per Set = 6          No. Sets    = 10 
          Randnum Seed       = 50078.53   Output to:  EXAMPLE1.TXT

             1  2  3  4  5  6
            -- -- -- -- -- --
   1:  1 -   6  3  5  1  4  2

   2:  1 -   2  5  6  1  3  4

   3:  1 -   1  2  4  3  6  5

   4:  1 -   3  5  4  1  2  6

   5:  1 -   5  1  4  3  2  6

   6:  1 -   1  5  3  2  6  4

   7:  1 -   1  6  5  3  2  4

   8:  1 -   1  4  3  2  6  5

   9:  1 -   4  1  5  2  6  3

  10:  1 -   2  4  5  3  1  6
  
  
  
Below is an example of randomly generating 50 targets of 1 to 4 for
5 subjects. 

        ****************** RNM Version (6D) ********************
                    Run at 13:56:36 on  03-30-2005

          No. Outcomes (1/P) = 4          Replacement = Y
          No. Trials per Set = 50         No. Sets    = 5 
          Randnum Seed       = 50195.74   Output to:  EXAMPLE2.TXT


             1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
            -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
   1:  1 -   4  2  3  1  4  3  4  2  3  2  1  1  2  1  2  2  2  3  1  4

      21 -   4  1  4  4  3  3  3  4  3  1  1  1  4  4  4  3  4  4  1  3

      41 -   4  4  3  1  1  4  3  1  4  4

   2:  1 -   3  1  4  1  3  2  2  2  4  2  2  1  1  4  4  2  2  1  1  1

      21 -   4  1  2  1  2  2  1  2  1  2  1  4  2  2  2  1  3  3  2  1

      41 -   2  3  3  3  3  1  2  3  2  1

   3:  1 -   3  3  2  1  2  2  1  1  3  3  1  1  2  3  3  1  4  4  1  3

      21 -   3  4  3  4  1  2  3  4  4  1  2  3  1  1  1  1  4  1  1  1

      41 -   2  2  2  1  3  1  3  4  3  3

   4:  1 -   4  2  4  4  3  2  1  2  4  4  2  3  2  1  4  2  3  2  1  2

      21 -   3  4  4  4  4  1  2  4  1  3  4  2  2  3  3  3  1  2  1  2

      41 -   4  4  3  3  2  1  3  1  4  3

   5:  1 -   3  1  1  2  4  3  3  2  1  4  1  4  1  4  2  2  3  3  3  2

      21 -   1  4  4  3  1  1  2  4  4  3  2  2  1  3  2  1  2  2  3  2

      41 -   3  2  2  4  4  4  4  3  4  1



Below is an example of compressed output for randomly selecting 2 targets
for 50 trials for 26 subjects.

12222112111122221221212222122122221121221212221222
22221221221121211212112121211221211211212212122212
11122211112221112111212112111122212122121111112211
22222211212211222222211221212122211211221121212212
22221221221111111111221221211222211212111221211122
22111112111221222121122111121122112111221221122221
22211222222222111112121221212221212222111112221121
12222212212211122122122221122211212121112121122122
12112211222112221221212222111111221212122121211111
21111112211212221211211111212121221122121221121211
11121211222122211222221221211211122212112121212121
22112111212122112122112212212222121222121211221121
12112222122222211221211221111121112111211211122222
22122211112111122112212112212211222212222211222211
22121211211122122112111112221222121111222222112121
22121221211122111221112211112122222211212211221222
22222122221112211221121121122111111122221111111111
12111121222212222211111222112122111112222212121222
21121221221212221122122122221111121211222122121222
22221212221112211122111211122221222221212121111111
22121211211122111222122222222111222122221211112222
22121121112112111221122212111221222221111221211111
12211121212222212222112211122222222121121222111112
21111122222122112122111121122111121122111112122212
21112122221121122211211212221222111212112121211221
21222112221222122112122121211111112222211122212111



-----------------------------------------------------------------------------

Technical information on rnm.exe.  

The program is written in MS QuickBasic.  

The random algorithm generates numbers uniformly distributed between 0 and 1
using the "subtractive algorithm" (p. 171) and "randomization by shuffling --
algorithm B" (p. 32) in the _The Art of Computer Programming_ 1981, by
Donald Knuth.  The basic idea for the combined algorithm was from  _Microsoft
QuickBasic Programmer's Toolbox_ 1988 by John Craig (pp. 355-364).

The entry point for the algorithm is obtained from the computer system clock
at the time the program is run.  The QuickBasic internal random generator is 
used to populate the shuffle arrays and then the algorithm is run 550 times 
to "warm up" the generator.

I checked the random algorithm with the frequency, runs up and down, and 
collision randomness tests as described in Knuth.

The randomization without replacement is done by filling an array and
then randomly swapping values.

The algorithm for randomly selecting a subset of numbers was from
Bissel, 1986, _Applied Statistics_, Vol 35, pp.73-75.

The source code is available for downloading in a zip file that also has the
program and this document.


  