HOW TO

Generate a random number within a range for labels using Arcade expressions in ArcGIS Online and Portal for ArcGIS Map Viewer

Last Published: January 5, 2023

Summary

In ArcGIS Online and Portal for ArcGIS Map Viewer, a random number within a range can be generated using Arcade expressions to label each feature on the map. This allows for a better visualization of the random classification on a map when performing predictive analysis.

This article provides an example and instructions using Arcade expressions to generate a random number within a range for labels in Map Viewer.

The image below shows a map in Map Viewer without random numbers on the polygon features.

The map without random digit labels in ArcGIS Online Map Viewer

Procedure

  1. Open the map in Map Viewer. Click Layers on the Contents (dark) toolbar, and select the layer with the pop-up for editing.
  2. On the Settings (light) toolbar, click Labels and turn on the Enable labels toggle button.
  3. Click Add label class.
  4. Click Use expression The Use expression icon and use the editor window to create the expression.
  5. In the editor window, specify a name for the new expression.
  6. In the Expression dialog box, insert the following Arcade expression.
Round(Random() * (<valueDigit1> - <valueDigit2>) + <valueDigit2> , <numberOfDecimal>)

The code block below is an example of the full working expression to generate a random round number between 0 to 50.

Round(Random() * (0 - 50) + 50 , 0)
  1. Click Run to preview the expression result. If the required result is achieved, click Done.
Specifying the Arcade expression in the ArcGIS Online Map Viewer editor window

The image below shows the labels with random numbers on the map in ArcGIS Online Map Viewer after running the Arcade expression.

The map in ArcGIS Online Map Viewer with randomized digit labels on each polygon

Article ID: 000028949

Software:
  • ArcGIS Online
  • Portal for ArcGIS

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options