User Tools

Site Tools


syntax:functions:random

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
syntax:functions:random [2016/06/20 11:57] dmitrysyntax:functions:random [2021/08/11 15:31] – [Examples] craigt
Line 1: Line 1:
-===== Random() =====+====== Random() =====
 +Category:  Number function
  
-Random number between 0 and 1.+\\  
 +=====Description===== 
 +This function generates a random number between 0 and 1
 + 
 +\\  
 +=====Arguments===== 
 +This function does not require arguments. 
 + 
 +**Return value type:**  Number 
 + 
 +\\  
 +=====Remarks===== 
 +====Generating random numbers within a given range==== 
 +To generate a random number between a specific minimum and maximum value, use the following calculation  (extra spaces have been added for clarity): 
 + 
 +  ( 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 )  //Excel-style rounding 
 +\\  
 +====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.  For example, the range between 20 and 40 includes //21// values. 
 + 
 + 
 +\\  
 +=====Examples===== 
 +Extra spaces added for clarity. 
 +  random() //Returns 0.37130572949209748204 
 + 
 +  ( random() * 10 ) +2   //Random number between 2 and 12, unrounded. 
 + 
 +  roundxl( ( random() * 20 ) +20 , 0 )  //Random number between 20 and 40, rounded to an integer.
  
-^  Example  ^  Result  ^ 
-| random()  |  0.37130572949209748204 | 
  
syntax/functions/random.txt · Last modified: 2021/10/15 14:56 by craigt

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki