Create random number
Function: Create random number
This function allows you to generate a random number and store it in a variable within your application's scope. You can specify the range for the number and choose whether it should be a whole number (integer) or a number with decimal places.
Input
- Minimum value: The smallest possible number that can be generated.
- Type: NUMBER
- Default: 0
- Maximum value: The largest possible number that can be generated.
- Type: NUMBER
- Default: 10
- Type generate: Choose whether to generate whole numbers (Integers) or numbers with decimal places (Decimals).
- Type: SELECT_ONE (options: Decimal, Integer)
- Default: Integer
Output
- Variable Name: The name of the variable where the generated random number is stored. By default, this variable will be named
RANDOM_NUMBER. The value stored in this variable will be aNUMBER(either an integer or a decimal, depending on your 'Type generate' selection).
Execution Flow
Real-Life Examples
Example 1: Generating a random whole number for a game score
Imagine you're building a simple game and want to assign a random score to a player at the end of a round.
- Inputs:
- Minimum value:
100 - Maximum value:
1000 - Type generate:
Integer - Variable Name:
PlayerScore
- Minimum value:
- Result: A new variable named
PlayerScoreis created, holding a random whole number between 100 and 1000 (e.g.,543).
Example 2: Simulating a random discount percentage
You want to offer customers a random discount on their next purchase, ranging from 5% to 20%, including decimal points for more variety.
- Inputs:
- Minimum value:
5 - Maximum value:
20 - Type generate:
Decimal - Variable Name:
DiscountPercentage
- Minimum value:
- Result: A new variable named
DiscountPercentageis created, holding a random number with decimal places between 5.0 and 20.0 (e.g.,12.75).
Example 3: Assigning a random order priority
For incoming customer orders, you want to assign a random priority level from 1 to 5, where 1 is the highest priority.
- Inputs:
- Minimum value:
1 - Maximum value:
5 - Type generate:
Integer - Variable Name:
OrderPriority
- Minimum value:
- Result: A new variable named
OrderPriorityis created, holding a random whole number between 1 and 5 (e.g.,3).