syntax:functions:random
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
syntax:functions:random [2016/06/20 11:57] – dmitry | syntax:functions:random [2021/10/15 14:56] (current) – Add See also section. craigt | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ===== Random() ===== | + | ====== Random() ====== |
+ | Category: | ||
- | Random | + | \\ |
+ | =====Description===== | ||
+ | This function generates a random | ||
- | ^ Example | + | \\ |
- | | random() | + | =====Arguments===== |
+ | This function does not require arguments. | ||
+ | **Return value type: | ||
+ | |||
+ | \\ | ||
+ | =====Remarks===== | ||
+ | ====Generating random numbers within a given range==== | ||
+ | To generate a random number between a specific minimum and maximum value, use the following calculation | ||
+ | |||
+ | ( random() * ( [number of values in range] - 1) ) + [minimum value] | ||
+ | |||
+ | The expression to generate a random number between 1 and 10 would be the following: | ||
+ | |||
+ | ( random() * (10-1) ) +1 | ||
+ | or | ||
+ | ( random() * 9 ) +1 | ||
+ | |||
+ | The expression above will provide a decimal result you will need to round for an integer result: | ||
+ | |||
+ | roundxl( ( random() * 9 ) +1 , 0 ) // | ||
+ | \\ | ||
+ | ====Determining the number of values in a given range==== | ||
+ | The number of values in a given range is determined as: | ||
+ | (max value) - (min value) + 1 | ||
+ | This can be deceiving at first glance. | ||
+ | |||
+ | |||
+ | \\ | ||
+ | =====Examples===== | ||
+ | Extra spaces added for clarity. | ||
+ | random() //Returns 0.37130572949209748204 | ||
+ | |||
+ | ( random() * 10 ) +2 // | ||
+ | |||
+ | roundxl( ( random() * 20 ) +20 , 0 ) //Random number between 20 and 40, rounded to an integer. | ||
+ | |||
+ | \\ | ||
+ | =====See also===== | ||
+ | * [[syntax: |
syntax/functions/random.1466438271.txt.gz · Last modified: 2016/06/20 11:57 by dmitry