Tuesday, January 5, 2016

How to populate Random Numbers in a field in ArcMap

Most of the time we are struggling to get random values in Arcmap Attribute table field. But its very simple with use of VB Script.

1. Add a Integer Field on your relevant attribute table and name it RandomValue.

2. Right Click on it and Select the Field Calculator

3. Select the Parser as VBScript

4. Ensure the Show Codeblock checkbox is ticked.

5. Paste the Following Code in Pre Logic Script Code text box;
                           dim max, min
           max=20
           min=5
           x=(Int((max-min+1)*Rnd+min))

In the equation above, max=20 and min=5 sets the maximum and minimum values that will be created in the field. No values will be  randomly created below 5 or above 20. If you want Change as your wish

6. Type in RandomValue text box
                  x

7. Click the Ok Button. You have done.


If you did not like to use VBScript you can Use the python also.

Pre-Logic Code for Python is

                               def fillRandomInt(intMin, intMax):
             import random
             return random.randint(int(intMin),int(intMax))

RandomValue=
                               fillRandomInt(1946,2010)


Here I made the limits are 1946 to 2010, You can change it according to your requirement.

0 comments: