Random number generators and streams

Random numbers are generated from algorithms that use seed values and other parameters to produce a sequence of random numbers. Such a series of random numbers is referred to as a random number stream. When creating models using random numbers, it is important to track which stream the random numbers are coming from. Sometimes all the random numbers for the different processes can come from the same stream, while other times each process may need unique streams.

There are many different number generators to create random numbers. The three methods in ArcGIS for generating random values (the generator types) are the Standard C Rand() function, ACM collected algorithm 599, and Mersenne Twister mt19937. You may want to reproduce the results from your models that use random numbers. To ensure reproducibility in models, a seed can be added as a parameter. If you specify the same seed for two different runs of the same model that use random values, the model will produce the same results.

The random number generator is either identified globally in the environment settings or within any tool that uses random values such as Calculate Value, Calculate Field, Create Random Raster, or Create Random Points. The random number generator starts a stream of random numbers based on the generator type and seed. The numbers are randomly determined, and the values are between 0 and 1. The numbers are created as needed.

In many cases, such as when the values are being used to model the uncertainty of the input data or model parameters, it is not effective to add pure random values to a tool. Usually, a priori information exists about the distribution of the uncertainty around the input data or the parameters in the model. Tools such as Create Random Raster, Calculate Value, and Calculate Field pull numbers from the random stream and transform them based on the distribution identified in the tool. For example, when adding random values to an input elevation surface with an accuracy of plus or minus two feet, if the model is run many times in an error analysis, more realizations should add values between 0 and 1 than 1 and 2. When using random values, the range of values, the distribution to use (for example, normal or Poisson), and distribution parameters (for example, the standard deviation) may be specified. Each value is independent of the other values.

There are multiple distributions available for assigning (or transforming) the values in the tools that use distributions (for example, Create Random Raster, Calculate Value, and Calculate Field). The distributions generally produce different results, and which distribution to select is determined by the end use. The distribution selected should be the best representation of the process being modeled.

See Distributions for assigning random values for a description of the available distributions and how they are generally used. See The distribution syntax for random values for the syntax and parameters for each distribution.

Setting the random stream globally

The Random Generator type and seed are set in the Random Numbers section of the Environment Settings dialog box. All subsequent tools that use random values—ArcGIS.Rand() (in Calculate Value and Calculate Field), Create Random Raster, and Create Random Points—will pull values from the stream. As each tool needs a random number, it will pull the next value from the global random stream.

Creating different random streams for each process

You may want unique streams for each process to make sure the process is independently random, to not bias your results, or to reproduce the output. You can create a stream locally by setting the random number generator and seed locally (for example, by clicking the Environments button on a tool or right-clicking a tool in ModelBuilder and clicking Properties). A new random stream is created, and when that tool needs a random value, it will pull only from this newly created stream. If the model iterates, the tool with the assigned random stream will continue to pull values from the local stream with each iteration. No other tools will pull values from the stream.

You can start as many local streams within a model as you want. You can also have a mixture of some tools pulling random values from the global stream while others pull values from their own local stream.

Altering a parameter randomly

Adding randomness to a parameter in a ModelBuilder model is a five-step process. In the following ModelBuilder example, the z-factor to the Spatial Analyst slope function will be randomly changed.

  1. Add the Slope tool from the Spatial Analyst Tools toolbox.
  2. Add the Calculate Value tool from the Data Management Tools toolbox.
    Random Parameters 2
    Random parameter 2
  3. Input an expression into the Calculate Value tool, and if randomness is to be added to the expression, input the ArcGIS.Rand() function into the expression with some arithmetic operation (or any expression). The expression to be processed in this example is arcgis.rand("Normal 2 2") * 2.
    Random Parameter 1
    Random parameter 1
  4. To make a relationship between the output of Calculate Value and the parameter to which randomness is being added (the z-factor in the Slope tool), open the Slope tool and, in the Z factor field, choose the output variable name from the drop-down list (output_value).
    Random Parameter 3
    Random parameter 3
  5. Right-click the Slope tool, click Properties, then make the output from the Calculate Value tool a precondition to the Slope tool. This last step ensures that the expression in the Calculate Value tool, the z-factor, will always be calculated prior to running the Slope tool.
    Random Parameter 4
    Random parameter 4
  6. Run the model.

Creating random values for randomly placed points

Assigning random values to randomly placed points is a three-step process. First, a specified number of points are placed with the Create Random Points tool. Second, the Add Field tool is used to create a new field in the output feature layer from the Create Random Points tool. Third, the Calculate Field tool is used to assign the random values to the newly created field by directly using the ArcGIS.Rand() function with a distribution as a simple expression or by using the ArcGIS.Rand() function in a complex expression.

5/7/2015