syntax:functions:random
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
syntax:functions:random [2016/06/20 11:57] – dmitry | syntax:functions:random [2021/08/11 15:30] – [Generating random numbers within a given range] craigt | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ===== Random() ===== | + | ====== Random() ====== |
+ | Category: | ||
- | Random | + | \\ |
+ | =====Description===== | ||
+ | This function generates a 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() = 0.37130572949209748204 | ||
+ | ( random() * 10 ) +2 // | ||
+ | roundxl( ( random() * 20 ) +20 , 0 ) //Random number between 20 and 40, rounded to integer. | ||
- | ^ Example | ||
- | | random() | ||
syntax/functions/random.txt · Last modified: 2021/10/15 14:56 by craigt