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

  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:


enter image description here

Result in a new float field:

enter image description here

  • +1 Answers that show examples and screenshots are especially helpful.
    – Aaron
    Jul 3 '16 at 2:37
  • 1
    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
    Oct 12 '17 at 5:09

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

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



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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