4

I need to generate random floating numbers between 0 and 1 in the field of attribute table for ArcGIS 10.3 version.

4

2 Answers 2

19
  1. In the field calculator, show Codeblock.

  2. In the pre-logic script code box:

    import random
    def randnum():
        return random.random()
    
  3. In the expression box:

    randnum()
    

enter image description here

Result in a new float field:

enter image description here

2
  • +1 Answers that show examples and screenshots are especially helpful.
    – Aaron
    Commented Jul 3, 2016 at 2:37
  • 2
    Just importing random in Pre-Logic Script and adding random.random() to the bottom input box yields the same result. One warning though, the field calculated should be a float or double type.
    – fatih_dur
    Commented Oct 12, 2017 at 5:09
3

You can vary parameter in expression below, depending on what distribution is required:

def aRand():
 return arcgis.rand("Normal 2 2")

---------------------------------------

aRand()

Not the answer you're looking for? Browse other questions tagged or ask your own question.