AnsweredAssumed Answered

Why is my Arcade expression only interpreted once unless I include an attribute value?

Question asked by AltErica on Dec 28, 2018
Latest reply on Dec 28, 2018 by AltErica

I am using the Calculate Field tool generate a random number between 0 and 180. I can do this with a Python codeblock. The following gives me a different random integer in each row:

def randomize():
    import random
    return random.randint(0,180)


I thought I could do it with an Arcade expression:

Round(Random() * 180, 0)

However, this gave me only one random number: each row had the same value, which isn't what I wanted. Apparently, the Arcade expression was calculated only once and its result was copied.


I found an awkward workaround, by including the OBJECTID in the expression:

($feature.OBJECTID * 0) + Round(Random() * 180, 0)

This, just like the Python codeblock, gave me different random numbers in each row. However, the Python codeblock didn't require me to specify a "dummy" value.


(Side note: including the attribute value didn't run significantly more slowly, even though there are thousands of rows in this feature class.)


Is it "as expected" behavior that an Arcade expression will only be interpreted once unless an attribute is included in the expression? It wasn't intuitively obvious to me.