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.
Solved! Go to Solution.
I can't say for sure why it doesn't work in Pro 2.2 (I think lack of cursor support), but when I set this up in Pro 2.3 (beta), I see this:
Hit Run again:
And again, just for good measure
I don't think cursors are supported using Arcade until Pro 2.3.
I can't say for sure why it doesn't work in Pro 2.2 (I think lack of cursor support), but when I set this up in Pro 2.3 (beta), I see this:
Hit Run again:
And again, just for good measure
I don't think cursors are supported using Arcade until Pro 2.3.
Gotcha -- I'm in Pro 2.1.3, so this is definitely not expected behavior but it will be addressed whenever we're able to upgrade our Pro version. Thank you!