WOLFRAM

gives a pseudorandom real number in the range 0 to 1.

RandomReal[{xmin,xmax}]

gives a pseudorandom real number in the range xmin to xmax.

RandomReal[xmax]

gives a pseudorandom real number in the range 0 to xmax.

RandomReal[range,n]

gives a list of n pseudorandom reals.

RandomReal[range,{n1,n2,}]

gives an n1×n2× array of pseudorandom reals.

Details and Options

  • RandomReal[{xmin,xmax}] chooses reals with a uniform probability distribution in the range xmin to xmax.
  • RandomReal[spec,WorkingPrecision->n] yields reals with n-digit precision. Leading or trailing digits in the generated number can turn out to be 0.
  • RandomReal gives a different sequence of pseudorandom reals whenever you run the Wolfram Language. You can start with a particular seed using SeedRandom.
  • A Method option to SeedRandom can be given to specify the pseudorandom generator used.

Examples

open allclose all

Basic Examples  (6)Summary of the most common use cases

A random real number in the range 0 to 1:

Out[1]=1

A random real number in the range to :

Out[1]=1

A random real number in the range 0 to 10:

Out[1]=1

Five random reals in the range 0 to 1:

Out[1]=1

A 3×2 array of random reals in the range to :

Out[1]=1

Random coordinates for 4 points in 3 dimensions:

Out[1]=1

Scope  (3)Survey of the scope of standard use cases

Generate random reals of any magnitude:

Out[1]=1

Generate random reals of any precision:

Out[1]=1
Out[2]=2

Generate low-precision reals:

Out[1]=1

Options  (1)Common values & functionality for each option

WorkingPrecision  (1)

Generate a random real with 50-digit precision:

Out[1]=1
Out[2]=2

Applications  (8)Sample problems that can be solved with this function

A random walk:

Out[2]=2

Circles at random positions:

Out[1]=1

Random array of gray levels:

Out[1]=1

Spheres at random positions:

Out[1]=1

Two-dimensional random walk:

Out[1]=1

Three-dimensional random walk:

Out[2]=2

Determinants of random 100×100 matrices:

Out[1]=1

Generate a complex number in the unit square:

Out[1]=1

Generate 5 complex numbers:

Out[2]=2

Use RandomComplex instead:

Out[3]=3

Generate exponential random variables using inversion method:

Compare sample histogram with the PDF of ExponentialDistribution:

Out[2]=2

Alternatively, use RandomVariate to sample from nonuniform distributions directly:

Test whether both datasets could be samples from the same distribution:

Out[4]=4

Properties & Relations  (5)Properties of the function, and connections to other functions

Use SeedRandom to get repeatable random values:

Out[1]=1
Out[2]=2

Use BlockRandom to block one use of RandomReal from affecting others:

Out[1]=1

With the same seed, RandomReal generates the "same" number, regardless of precision:

Out[1]=1

RandomReal generates a uniform distribution, here with mean 0.5:

Out[1]=1

RandomReal generates white noise:

Out[1]=1

Neat Examples  (1)Surprising or curious use cases

Construct a surface from random heights:

Out[2]=2
Wolfram Research (2007), RandomReal, Wolfram Language function, https://reference.wolfram.com/language/ref/RandomReal.html.
Wolfram Research (2007), RandomReal, Wolfram Language function, https://reference.wolfram.com/language/ref/RandomReal.html.

Text

Wolfram Research (2007), RandomReal, Wolfram Language function, https://reference.wolfram.com/language/ref/RandomReal.html.

Wolfram Research (2007), RandomReal, Wolfram Language function, https://reference.wolfram.com/language/ref/RandomReal.html.

CMS

Wolfram Language. 2007. "RandomReal." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/RandomReal.html.

Wolfram Language. 2007. "RandomReal." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/RandomReal.html.

APA

Wolfram Language. (2007). RandomReal. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/RandomReal.html

Wolfram Language. (2007). RandomReal. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/RandomReal.html

BibTeX

@misc{reference.wolfram_2025_randomreal, author="Wolfram Research", title="{RandomReal}", year="2007", howpublished="\url{https://reference.wolfram.com/language/ref/RandomReal.html}", note=[Accessed: 26-March-2025 ]}

@misc{reference.wolfram_2025_randomreal, author="Wolfram Research", title="{RandomReal}", year="2007", howpublished="\url{https://reference.wolfram.com/language/ref/RandomReal.html}", note=[Accessed: 26-March-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_randomreal, organization={Wolfram Research}, title={RandomReal}, year={2007}, url={https://reference.wolfram.com/language/ref/RandomReal.html}, note=[Accessed: 26-March-2025 ]}

@online{reference.wolfram_2025_randomreal, organization={Wolfram Research}, title={RandomReal}, year={2007}, url={https://reference.wolfram.com/language/ref/RandomReal.html}, note=[Accessed: 26-March-2025 ]}