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?
Solved! Go to Solution.
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
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
This works, but how can one get it to work by generating whole numbers? Currently, this is set up to produce floats or doubles.
You can use Round() and set it to 0 to return whole numbers i.e. Round(x,0)
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
1/28/2025 - If anyone comes across this and wants to do this in AGOL Smart Forms below is a method to make more of a string. Sort of like a hexcode value. Due to Arcade and not being pure JavaScript its a bit difficult to develop so going basic and simple like the below helps for numbers, letters, or numbers and letters.
///FL = Field Location
var prefix = 'FL';
var letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var num1 = Text(Floor(Random() * 10));
var num2 = Text(Floor(Random() * 10));
var num3 = Text(Floor(Random() * 10));
var letter1 = Mid(letters, Floor(Random() * 26) + 1, 1);
var letter2 = Mid(letters, Floor(Random() * 26) + 1, 1);
var letter3 = Mid(letters, Floor(Random() * 26) + 1, 1);
return prefix + num1 + num2 + num3 + letter1 + letter2 + letter3