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

From Apache OpenOffice Wiki
Jump to: navigation, search
(Initial content)
 
(added that 0<=n<1)
Line 3: Line 3:
 
== RAND ==
 
== RAND ==
 
Returns a random number between 0 and 1.
 
Returns a random number between 0 and 1.
 
  
 
=== Syntax: ===
 
=== Syntax: ===
 
<tt>'''RAND()'''</tt>
 
<tt>'''RAND()'''</tt>
: This function produces a new random number each time Calc recalculates.
+
: This function produces a new random number each time Calc recalculates, greater than or equal to 0, and less than 1.
  
 
: To force Calc to recalculate manually press Shift+Ctrl+F9.
 
: To force Calc to recalculate manually press Shift+Ctrl+F9.
  
 
: To generate a random number which never recalculates, copy a cell containing <tt>'''=RAND()'''</tt>, 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 <tt>'''=RAND()'''</tt>, and use Edit - Paste Special... (with Paste All and Formulas <u>not</u> selected and Numbers selected).
 
  
 
=== Example: ===
 
=== Example: ===
 
<tt>'''RAND()'''</tt>
 
<tt>'''RAND()'''</tt>
: returns a random number between <tt>'''0'''</tt> and <tt>'''1'''</tt>.
+
: returns a random number between <tt>'''0'''</tt> (inclusive) and <tt>'''1'''</tt> (exclusive).
  
 
<tt>'''RAND()*(b-a) + a'''</tt>
 
<tt>'''RAND()*(b-a) + a'''</tt>
 
: returns a random real number between <tt>'''a'''</tt> and <tt>'''b'''</tt>.
 
: returns a random real number between <tt>'''a'''</tt> and <tt>'''b'''</tt>.
 
  
 
=== See also: ===
 
=== See also: ===

Revision as of 16:09, 3 January 2008


RAND

Returns a random number between 0 and 1.

Syntax:

RAND()

This function produces a new random number each time Calc recalculates, greater than or equal to 0, and less than 1.
To force Calc to recalculate manually press Shift+Ctrl+F9.
To generate a random number which never recalculates, copy a cell containing =RAND(), and use Edit - Paste Special... (with Paste All and Formulas not selected and Numbers selected).

Example:

RAND()

returns a random number between 0 (inclusive) and 1 (exclusive).

RAND()*(b-a) + a

returns a random real number between a and b.

See also:

RANDBETWEEN

Mathematical functions

Personal tools