Bruce Mitchell Bruce Mitchell - 4 months ago 19
Python Question

Random number generation with Python, ArcGIS 10.1

I have a shapefile with 1,000+ cases and three fields (DOUBLE) ran1, ran2 and ran3, which I have set up to receive the product of separate random number generation operations.

Unfortunately, the Random Number Generator (Environment setting) documentation and Parser:Python do not seem to be appropriate for this sort of thing.

getRandomValue()
import numpy.random as R
def getRandomValue(fieldName1):
return R.random()


Any ideas are welcome.

Answer

I'm not sure why you deem the code you posted as not appropriate.

For me the code below works great and to get random values written into fields you would just wrap it in an UpdateCursor.

import numpy.random as R

def getRandomValue(fieldName1):
    return R.random()

print getRandomValue()

If the range of random numbers is not suitable then this StackOverflow Question has a good Answer.

Please note that the GIS Stack Exchange might have been a good alternative location to post this Question because it uses ArcPy from ArcGIS.

Comments