Create Random Points (Data Management)

License Level:BasicStandardAdvanced

Summary

Creates a specified number of random point features. Random points can be generated in an extent window, inside polygon features, on point features, or along line features.

Learn more about how Create Random Points works

Usage

Syntax

CreateRandomPoints_management (out_path, out_name, {constraining_feature_class}, {constraining_extent}, {number_of_points_or_field}, {minimum_allowed_distance}, {create_multipoint_output}, {multipoint_size})
ParameterExplanationData Type
out_path

The location or workspace in which the random points feature class will be created. This location or workspace must already exist.

Feature Dataset;Workspace
out_name

The name of the random points feature class to be created.

String
constraining_feature_class
(Optional)

Random points will be generated inside or along the features in this feature class. The constraining feature class can be point, multipoint, line, or polygon. Points will be randomly placed inside polygon features, along line features, or at point feature locations. Each feature in this feature class will have the specified number of points generated inside it (for example, if you specify 100 points, and the constraining feature class has 5 features, 100 random points will be generated in each feature, totaling 500 points).

Feature Layer
constraining_extent
(Optional)

Random points will be generated inside the extent. The constraining extent will only be used if no constraining feature class is specified.

Extent;Feature Layer;Raster Layer
number_of_points_or_field
(Optional)

The number of points to be randomly generated.

The number of points can be specified as a long integer number or as a field from the constraining features containing numeric values for how many random points to place within each feature. The field option is only valid for polygon or line constraining features. If the number of points is supplied as a long integer number, each feature in the constraining feature class will have that number of random points generated inside or along it.

Field;Long
minimum_allowed_distance
(Optional)

The shortest distance allowed between any two randomly placed points. If a value of 1 Meter is specified, all random points will be farther than 1 meter away from the closest point.

Field;Linear unit
create_multipoint_output
(Optional)

Determines if the output feature class will be a multipart or single-part feature.

  • POINTThe output will be geometry type point (each point is a separate feature). This is the default.
  • MULTIPOINTThe output will be geometry type multipoint (all points are a single feature).
Boolean
multipoint_size
(Optional)

If the Create Multipoint Output option is used (checked/MULTIPOINT), this parameter specifies the number of random points to be placed in each multipoint geometry.

Long

Code Sample

CreateRandomPoints example 1 (Python window)

The following Python window script demonstrates how to use the CreateRandomPoints tool in immediate mode:

import arcpy
arcpy.CreateRandomPoints_management("c:/data/project", "samplepoints", "c:/data/studyarea.shp", "", 500, "", "POINT", "")
CreateRandomPoints with Random Values example 2 (stand-alone Python script)

The following stand-alone Python script demonstrates how to create random points with random values:

#Name: RandomPointsRandomValues.py
#Purpose: create random points with random values

# Import system modules
import arcpy, os, random
from arcpy import env

# Create random points in the features of a constraining feature class
# Number of points for each feature determined by the value in the field specified
outGDB = "C:/data/county.gdb"
outName = "randpeople"
conFC = "C:/data/county.gdb/blocks"
numField = "POP2000"
arcpy.CreateRandomPoints_management(outGDB, outName, conFC, "", numField)

# set workspace
env.workspace = "C:/data/county.gdb"

# Create fields for random values
fieldInt = "fieldInt"
fieldFlt = "fieldFlt"
arcpy.AddField_management(outName, fieldInt, "LONG") # add long integer field
arcpy.AddField_management(outName, fieldFlt, "FLOAT") # add float field

# Calculate random values between 1-100 in the new fields
arcpy.CalculateField_management(outName, fieldInt, "random.randint(1,100)","PYTHON","import random")
arcpy.CalculateField_management(outName, fieldFlt, "random.uniform(1,100)","PYTHON","import random")
CreateRandomPoints example 3 (stand-alone Python script)

The following stand-alone Python script demonstrates several methods to use the CreateRandomPoints tool:

#Name: RandomPoints.py
#Purpose: create several types of random points feature classes

# Import system modules
import arcpy, os
from arcpy import env

#set environment settings
env.overWriteOutput = True

# Create random points in an extent defined simply by numbers
outFolder = "C:/data"
numExtent = "0 0 1000 1000"
numPoints = 100
outName = "myRandPnts.shp"
env.outputCoordinateSystem = "Coordinate Systems/Projected Coordinate Systems/World/Miller Cylindrical (world).prj"
arcpy.CreateRandomPoints_management(outFolder, outName, "", numExtent, numPoints)
env.outputCoordinateSystem = ""
 
# Create random points in an extent defined by another feature class
outName = "testpoints.shp"
fcExtent = "C:/data/studyarea.shp"
arcpy.CreateRandomPoints_management(outFolder, outName, "", fcExtent, numPoints)
 
# Create random points in the features of a constraining feature class
# Number of points for each feature determined by the value in the field specified
outGDB = "C:/data/county.gdb"
outName = "randpeople"
conFC = "C:/data/county.gdb/blocks"
numField = "POP2000"
arcpy.CreateRandomPoints_management(outGDB, outName, conFC, "", numField)

#create random points in the features of a constraining 
#feature class with a minimum allowed distance
outName = "constparcelpnts"
conFC = "C:/data/county.gdb/parcels"
numPoints = 10
minDistance = "5 Feet"
arcpy.CreateRandomPoints_management(outGDB, outName, conFC, "", numPoints, minDistance) 

#Create random points with a multipoint output
outName = "randomMPs"
fcExtent = "C:/data/county.gdb/county"
numPoints = 100
numMP = 10
arcpy.CreateRandomPoints_management(outGDB, outName, "", fcExtent, numPoints, "", "MULTIPOINT", numMP)

Environments

Related Topics

Licensing Information

ArcGIS for Desktop Basic: Requires 3D Analyst or Spatial Analyst
ArcGIS for Desktop Standard: Requires 3D Analyst or Spatial Analyst
ArcGIS for Desktop Advanced: Yes
11/18/2013