Select to view content in your preferred language

# Arcade : Generate Random # Between X and Y

7464
4
Jump to solution
03-08-2018 07:20 AM
Honored Contributor

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)
1 Solution

Accepted Solutions
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‍``
4 Replies
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‍``
Emerging Contributor

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

Esri Contributor

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

Frequent Contributor

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