# Generating random valued random points using ArcPy?

I want my area filled radomly with a number of points with a number of random numerical values in the range i specify. Other than tediously creating each point and filling up random values, is there any better method?

If you have an Advanced license or Spatial Analyst or 3D Analyst, you can use the Create Random Points tool.

You can then add a field and populate it with random values within a specified range with this Python code snippet (change the `fc`, `field_name` and range values, then copy-paste the code in the Python window in ArcMap or ArcCatalog):

``````import arcpy, random
with arcpy.da.UpdateCursor(fc, "field_name") as cur:
for row in cur:
row[0] = random.randint(0, 100)
cur.updateRow(row)
``````

This will generate integer values between 0 and 100. Python offers other random functions if you need another type of range.

• Thanks. Generating random points was easy. But I am not being able to generate random values for those points. When I use the expression you gave, all the values of the field get populated by a single random value. There is no variation in its value. How do I solve this problem? Sep 29, 2016 at 11:29
• Sorry, I've modified my answer to generate different random values for each row. Using Python is necessary for this. Sep 29, 2016 at 11:41
• By the way, which version of ArcGIS do you use? The Calculate Field expression I first suggested should work, but there is a bug in 10.2.1 - which doesn't seem to be solved yet anyway. Sep 29, 2016 at 11:52
• Its 10.3 but your code is not working. Could you see what mistake I did? I know nothing of python u know and I am new in GIS too. >>> import arcpy, random ... with arcpy.da.UpdateCursor("random_points","rainfall_in_mm") as cur: ... for row in cur: ... row[0]=random.randint(1000, 1400) ... cur.updateRow(row) ... Parsing error IndentationError: unexpected indent (line 1) >>> Sep 29, 2016 at 12:04
• Make sure you respect the structure, indentation is important with Python: 0 tabs at line 1 and 2 - 1 tab at line 3 - 2 tabs at lines 4 & 5. Sep 29, 2016 at 12:07