RandomReal
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 allBasic Examples (6)
Scope (3)
Applications (8)
Three-dimensional random walk:
Determinants of random 100×100 matrices:
Generate a complex number in the unit square:
Use RandomComplex instead:
Generate exponential random variables using inversion method:
Compare sample histogram with the PDF of ExponentialDistribution:
Alternatively, use RandomVariate to sample from nonuniform distributions directly:
Test whether both datasets could be samples from the same distribution:
Properties & Relations (5)
Use SeedRandom to get repeatable random values:
Use BlockRandom to block one use of RandomReal from affecting others:
With the same seed, RandomReal generates the "same" number, regardless of precision:
RandomReal generates a uniform distribution, here with mean 0.5:
RandomReal generates white noise:
Text
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.
APA
Wolfram Language. (2007). RandomReal. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/RandomReal.html