Arcade : Generate Random # Between X and Y

6343
4
Jump to solution
03-08-2018 07:20 AM
BrianO_keefe
Occasional Contributor III

Arcade is excellent. I'm digging in and using it alot. But one of the things I am finding a need for is to generate random numbers. I build a lot of demo maps with fake data. I have to generate fake budgets, fake dates, etc. I generally just 'lorem ipsum' for descriptions but I need to be able to better generate more (close to) realistic numbers.

Does anyone know how I could do this with Arcade?

My preference would be Random(x) to get a number between 0 and X. But that isn't to be.

Anyone?

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

Since Random (Math Functions | ArcGIS for Developers ) returns a value between 0 and 1 you just multiply with the value you want to use as upper boundary:

Random() * X

If you want a value between A and B, you can do this:

Random() * (B - A) + A

View solution in original post

4 Replies
XanderBakker
Esri Esteemed Contributor

Since Random (Math Functions | ArcGIS for Developers ) returns a value between 0 and 1 you just multiply with the value you want to use as upper boundary:

Random() * X

If you want a value between A and B, you can do this:

Random() * (B - A) + A
adam_gallaher
New Contributor II

This works, but how can one get it to work by generating whole numbers? Currently, this is set up to produce floats or doubles. 

0 Kudos
Sarah_Saint-Ruth
Esri Contributor

You can use Round() and set it to 0 to return whole numbers i.e. Round(x,0)

anonymous55
Occasional Contributor II

Hello @Sarah_Saint-Ruth @XanderBakker 

I need to create new field with unique ID for hosted layer which already published in AGOL. I can't find any Arcade code for creating unique ID for new field in AGOL . I am thinking about to copy object id to new field but I don't know the arcade code for it.

I will appreciate any help

0 Kudos