Arcade : Generate Random # Between X and Y

2517
3
Jump to solution
03-08-2018 07:20 AM
BrianO_keefe
Regular Contributor II

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

3 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)