ArcGIS Toolbox – Generate Random Points with ArcPy

Share Button

Updated – 2/27/2015
Fixed compatibility with Python 3 for ArcGIS Pro

(If you’re using Firefox, then right click and Save Link As)
Download the Generate Random Points Toolbox – works with ArcGIS 10.1+
View the Source Code

(any donations go towards hosting costs)

Maybe you’re doing a soil analysis study (check out my Create Custom Grid tool) and need random locations for each sample? Or you’re doing a tree diversity study and need random locations where the number of tree species will be identified? Or maybe you’re just looking for an adventure and want to visit each random location created from a polygon around a city neighborhood? Who knows…

The Generate Random Points tool generates a number of random points inside each polygon of an input Polygon feature class. The number of random points can be a fixed number or based on a field.

An optional parameter can be set to define a minimum distance between the random points. There is also a parameter called Maximum Attempts, which is the maximum attempts the tool will make before failure. Depending on the number of random points and the minimum distance, there might not be a possible solution so the tool would run indefinitely.

If the maximum attempts for a polygon is reached, there are 3 choices on how to handle:

NO – The tool will fail and no random points will be generated.
KEEP_ALL – All generated random points will be returned. If one polygon could only generate 20 out of 100 random points, the 20 points will be included in the output.
KEEP_ONLY_SUCCESSFUL – Only polygons that succesfully generated all the required random points will have the random points included in the output.

The output Point feature class will contain a field called PolygonOID, which states the OID of the Polygon that each point was generated from.

Be sure to view the Tool Help within the tool dialog box for detailed instructions. Also, check the Geoprocessing Results for any error messages.

A similar ESRI tool called Create Random Points requires ArcInfo (Advanced) licensing.
This tool only requires ArcGIS 10.1 or later at any licensing level.

Here’s a screenshot of the parameters:
Generate Random Points params

Here’s an example of generating 20 random points:
Generate Random Points

Here’s an example of generating 20 random points with a minimum distance of 200 feet:
Generate Random Points Min Distance

I hope someone can find this tool useful. Please leave a comment if you have any questions or problems, and be sure to check out the other tools I’ve created!

24 thoughts on “ArcGIS Toolbox – Generate Random Points with ArcPy

Leave a Reply