Difference between revisions of "Documentation/How Tos/Calc: RANDBETWEEN function"

From Apache OpenOffice Wiki
Jump to: navigation, search
m
m
Line 5: Line 5:
  
 
This function is only available if the '''Analysis AddIn''' is installed.  
 
This function is only available if the '''Analysis AddIn''' is installed.  
 
  
 
=== Syntax: ===
 
=== Syntax: ===
Line 14: Line 13:
  
 
: To generate a random number which never recalculates, copy a cell containing this function, and use '''Edit - Paste Special...''' (with '''Paste All''' and '''Formulas''' <u>not</u> selected and '''Numbers''' selected).
 
: To generate a random number which never recalculates, copy a cell containing this function, and use '''Edit - Paste Special...''' (with '''Paste All''' and '''Formulas''' <u>not</u> selected and '''Numbers''' selected).
 
  
 
: An alternative to this function not requiring the Analysis AddIn would be:
 
: An alternative to this function not requiring the Analysis AddIn would be:
 
: <tt>'''INT(RAND()*(top-bottom+1))+bottom'''</tt>.
 
: <tt>'''INT(RAND()*(top-bottom+1))+bottom'''</tt>.
 
  
 
=== Example: ===
 
=== Example: ===
 
<tt>'''RANDBETWEEN(20; 30)'''</tt>
 
<tt>'''RANDBETWEEN(20; 30)'''</tt>
 
: returns an integer between <tt>'''20'''</tt> and <tt>'''30'''</tt> (inclusive).
 
: returns an integer between <tt>'''20'''</tt> and <tt>'''30'''</tt> (inclusive).
 
  
 
=== See also: ===
 
=== See also: ===

Revision as of 07:06, 2 March 2008


RANDBETWEEN

Returns an integer random number in a specified range.

This function is only available if the Analysis AddIn is installed.

Syntax:

RANDBETWEEN(bottom; top)

Returns an integer random number between integers bottom and top (both inclusive).
This function produces a new random number each time Calc recalculates. To force Calc to recalculate manually press Shift+Ctrl+F9.
To generate a random number which never recalculates, copy a cell containing this function, and use Edit - Paste Special... (with Paste All and Formulas not selected and Numbers selected).
An alternative to this function not requiring the Analysis AddIn would be:
INT(RAND()*(top-bottom+1))+bottom.

Example:

RANDBETWEEN(20; 30)

returns an integer between 20 and 30 (inclusive).

See also:

RAND

Mathematical functions

Personal tools