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)<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
I thought I could do it with an Arcade expression:
Round(Random() * 180, 0)<SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
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)<SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
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.