Create Random Raster (Spatial Analyst)

Available with Spatial Analyst license.

Summary

Creates a raster of random floating-point values between 0.0 and 1.0 within the extent and cell size of the analysis window.

The Create Random Raster tool in the Data Management toolbox provides enhanced functionality or performance.

Illustration

Create Random Raster illustration
OutRas = CreateRandomRaster()
Note: This output is representative. The actual values will be different each time the tool is executed.

Usage

  • The Create Random Raster tool generates values for every cell in the output raster.

  • The output raster from this tool is always floating point.

  • The cell values will have up to 7 digits of precision after the decimal point.

  • Repeatedly using the same seed value or the default will not produce the same raster.

  • You can change the seed through a parameter to ensure you obtain different starting points for the random number generator.

  • To generate the values, the ACM algorithm 599 random number generator is used.

  • The Output cell size parameter can be defined by a numeric value or obtained from an existing raster dataset. If the cell size hasn’t been explicitly specified as the parameter value, it is derived from the Cell Size environment if it has been specified. If the parameter cell size or the environment cell size has not been specified, but the Snap Raster environment has been set, the cell size of the snap raster is used. If nothing is specified, the cell size is 1.

  • If the cell size is specified using a numeric value, the tool will use it directly for the output raster.

    If the cell size is specified using a raster dataset, the parameter will show the path of the raster dataset instead of the cell size value. The cell size of that raster dataset will be used directly in the analysis, provided the spatial reference of the dataset is the same as the output spatial reference. If the spatial reference of the dataset is different than the output spatial reference, it will be projected based on the specified Cell Size Projection Method value.

  • Since the tool does not have any input, the output spatial reference is derived from other settings in a particular order. First, the Output Coordinate System environment will be used, if specified, followed by the coordinate system of the map view. If neither of these conditions are met, the output spatial reference will be set to Unknown.

  • Based on the cell size, the default output extent is computed to create a raster of 250 rows and 250 columns. Thus, for the default cell size of 1, the Output extent is (0, 0, 250, 250). The extent value is adjusted based on the Cell Size, Snap Raster, and Output Coordinate System environments, if specified.

  • The Data Management toolbox has a Create Random Raster tool that offers some more options for the distribution of the values.

  • See Analysis environments and Spatial Analyst for additional details on the geoprocessing environments that apply to this tool.

Parameters

LabelExplanationData Type
Seed value
(Optional)

A value to be used to reseed the random number generator.

This may be an integer or floating-point number. Rasters are not permitted as input.

The random number generator is automatically seeded with the current value of the system clock (seconds since January 1, 1970). The range of permissible values for the seed value is -231 + 1 to 231 (or -2,147,483,647 to 2,147,483,648).

Double
Output cell size
(Optional)

The cell size of the output raster that will be created.

This parameter can be defined by a numeric value or obtained from an existing raster dataset. If the cell size hasn't been explicitly specified as the parameter value, the environment cell size value will be used if specified; otherwise, additional rules will be used to calculate it from the other inputs. See the usage section for more detail.

Analysis Cell Size
Output extent
(Optional)

The extent for the output raster dataset.

The extent will be the value in the environment if specifically set. If not specifically set, the default is 0, 0, 250, 250.

Envelope; Extent

Return Value

LabelExplanationData Type
Output raster

The output raster of randomly distributed values with a range of 0.0 to 1.0

Raster

CreateRandomRaster({seed_value}, {cell_size}, {extent})
NameExplanationData Type
seed_value
(Optional)

A value to be used to reseed the random number generator.

This may be an integer or floating-point number. Rasters are not permitted as input.

The random number generator is automatically seeded with the current value of the system clock (seconds since January 1, 1970). The range of permissible values for the seed value is -231 + 1 to 231 (or -2,147,483,647 to 2,147,483,648).

Double
cell_size
(Optional)

The cell size of the output raster that will be created.

This parameter can be defined by a numeric value or obtained from an existing raster dataset. If the cell size hasn't been explicitly specified as the parameter value, the environment cell size value will be used if specified; otherwise, additional rules will be used to calculate it from the other inputs. See the usage section for more detail.

Analysis Cell Size
extent
(Optional)

The extent for the output raster dataset.

The Extent is a Python class.

In this tool, it is in the form Extent(XMin, YMin, XMax, YMax)

  • where XMin and YMin define the lower left coordinate of the extent, and XMax and YMax define the upper right coordinate.

The coordinates are specified in the same map units as the Output Coordinate System environment setting.

The extent will be the value in the environment if specifically set. If not specifically set, the default is 0, 0, 250, 250.

Envelope; Extent

Return Value

NameExplanationData Type
out_raster

The output raster of randomly distributed values with a range of 0.0 to 1.0

Raster

Code sample

CreateRandomRaster example 1 (Python window)

This sample creates an output raster of random values at the defined cell size and extent.

import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "C:/sapyexamples/data"
outRandRaster = CreateRandomRaster(100, 2, Extent(0, 0, 150, 150))
outRandRaster.save("C:/sapyexamples/output/outrandom")
CreateRandomRaster example 2 (stand-alone script)

This sample creates an output raster of random values at the defined cell size and extent.

# Name: CreateRandomRaster_Ex_02.py
# Description: Creates a raster of random floating point values
#              between 0 and 1
# Requirements: Spatial Analyst Extension

# Import system modules
import arcpy
from arcpy import env
from arcpy.sa import *

# Set environment settings
env.workspace = "C:/sapyexamples/data"

# Set local variables
seedValue = 1
cellSize = 2
extent = Extent(0, 0, 150, 150)

# Execute CreateRandomRaster
outRandomRaster = CreateRandomRaster(seedValue, cellSize, extent) 

# Save the output 
outRandomRaster.save("C:/sapyexamples/output/outrand")

Licensing information

  • Basic: Requires Spatial Analyst
  • Standard: Requires Spatial Analyst
  • Advanced: Requires Spatial Analyst

Related topics