How do I generate a random number within provided range of integers
This example demonstrates generating a random number from a provided range of integers.
In the solution below:
Approach 1: A random number is generated using the "storeRandomNumber" command by specifying the integer value in target. If you pass the integer value as 2, then a 2-digit random number is generated and stored in the variable "randomNumber".
Approach 2: A random number is generated using the "storeRandomNumber" command by specifying a range in target. If you pass the range as 1-100, then a random number between 1 to 100 is generated and stored in the variable "randomNumber".
Solution:
Approach1: Using integer
# | Command | Target | Value |
---|---|---|---|
Generate a random number using integer | |||
1 | storeRandomNumber |
2 |
randomNumber |
Approach2: Using specific range
# | Command | Target | Value |
---|---|---|---|
Generate a random number using range | |||
1 | storeRandomNumber |
1-100 |
randomNumber |
Tips, Tricks, Gotchas & Best Practices:
- For integer approach, the number of digits the command should generate should be less than 10.
- The range should not be provided in single or double quotes.
- The range should be hyphen separated with or without spaces before and after the hyphen.