({{, (RefLink[RandomReal, paclet:ref/RandomReal])[]
gives a pseudorandom real number in the range 0 to 1. }, {, (RefLink[RandomReal, paclet:ref/RandomReal])[{(Subscript[x, min]),(Subscript[x, max])}]
gives a pseudorandom real number in the range (Subscript[x, min]) to (Subscript[x, max]). }, {, (RefLink[RandomReal, paclet:ref/RandomReal])[(Subscript[x, max])]
gives a pseudorandom real number in the range 0 to (Subscript[x, max]).}, {, (RefLink[RandomReal, paclet:ref/RandomReal])[range,n]
gives a list of n pseudorandom reals. }, {, (RefLink[RandomReal, paclet:ref/RandomReal])[range,{(Subscript[n, 1]),(Subscript[n, 2]),…}]
gives an (Subscript[n, 1])×(Subscript[n, 2])×… array of pseudorandom reals. }})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[RandomReal, paclet:ref/RandomReal])[{(Subscript[x, min]),(Subscript[x, max])}] chooses reals with a uniform probability distribution in the range (Subscript[x, min]) to (Subscript[x, max]).

(RefLink[RandomReal, paclet:ref/RandomReal])[spec,(RefLink[WorkingPrecision, paclet:ref/WorkingPrecision])->n] yields reals with n-digit precision. Leading or trailing digits in the generated number can turn out to be 0.

(RefLink[RandomReal, paclet:ref/RandomReal]) gives a different sequence of pseudorandom reals whenever you run the Wolfram Language. You can start with a particular seed using (RefLink[SeedRandom, paclet:ref/SeedRandom]).

A (RefLink[Method, paclet:ref/Method]) option to (RefLink[SeedRandom, paclet:ref/SeedRandom]) can be given to specify the pseudorandom generator used.

OpenersPrimaryExamplesSection(Spacer1)Examples  (24)

OpenersExampleSection0(Spacer1)Basic Examples  (6)

A random real number in the range 0 to 1:

RandomReal[]

A random real number in the range -10 to 10:

RandomReal[{-10,10}]

A random real number in the range 0 to 10:

RandomReal[10]

Five random reals in the range 0 to 1:

RandomReal[1,5]

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

RandomReal[{-1,1},{3,2}]

Random coordinates for 4 points in 3 dimensions:

RandomReal[1,{4,3}]

OpenersExampleSection1(Spacer1)Scope  (3)

Generate random reals of any magnitude:

RandomReal[10^1000]

Generate random reals of any precision:

RandomReal[WorkingPrecision->30]

RandomReal[10^1000,WorkingPrecision->50]

Generate low-precision reals:

RandomReal[{-1,1},5,WorkingPrecision->5]

OpenersExampleSection2(Spacer1)Options  (1)

OpenersExampleSubsection0(Spacer1)WorkingPrecision  (1)

Generate a random real with 50-digit precision:

RandomReal[WorkingPrecision->50]

RandomReal[{-1,1},WorkingPrecision->50]

OpenersExampleSection3(Spacer1)Applications  (8)

A random walk:

ListLinePlot[Accumulate[RandomReal[{-1,1},100]]]

Circles at random positions:

Graphics[Circle/@RandomReal[10,{40,2}]]

Random array of gray levels:

ArrayPlot[RandomReal[1,{30,40}]]

Spheres at random positions:

Graphics3D[Sphere/@RandomReal[10,{50,3}]]

Two-dimensional random walk:

Graphics[Line[Accumulate[RandomReal[{-1,1},{500,2}]]]]

Three-dimensional random walk:

Graphics3D[Line[Accumulate[RandomReal[{-1,1},{500,3}]]]]

Determinants of random 100×100 matrices:

Table[Det[RandomReal[1,{100,100}]],{10}]

Generate a complex number in the unit square:

RandomReal[1,2].{1,I}

Generate 5 complex numbers:

RandomReal[1,{5,2}].{1,I}

Use (RefLink[RandomComplex, paclet:ref/RandomComplex]) instead:

RandomComplex[1+I,5]

Generate exponential random variables using inversion method:

sample=InverseCDF[ExponentialDistribution[1],RandomReal[1,10^4]];

Compare sample histogram with the PDF of (RefLink[ExponentialDistribution, paclet:ref/ExponentialDistribution]):

Show[Histogram[sample,Automatic,PDF],Plot[PDF[ExponentialDistribution[1],x],{x,0,6}]]

Alternatively, use (RefLink[RandomVariate, paclet:ref/RandomVariate]) to sample from nonuniform distributions directly:

sample2=RandomVariate[ExponentialDistribution[1],10^4];

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

KolmogorovSmirnovTest[sample,sample2,"TestConclusion"]

OpenersExampleSection4(Spacer1)Properties & Relations  (5)

Use (RefLink[SeedRandom, paclet:ref/SeedRandom]) to get repeatable random values:

{RandomReal[],RandomReal[]}

{SeedRandom[1234];RandomReal[],SeedRandom[1234];RandomReal[]}

Use (RefLink[BlockRandom, paclet:ref/BlockRandom]) to block one use of (RefLink[RandomReal, paclet:ref/RandomReal]) from affecting others:

{BlockRandom[RandomReal[]],RandomReal[]}

With the same seed, (RefLink[RandomReal, paclet:ref/RandomReal]) generates the "same" number, regardless of precision:

Table[SeedRandom[4567];RandomReal[WorkingPrecision->p],{p,10}]

(RefLink[RandomReal, paclet:ref/RandomReal]) generates a uniform distribution, here with mean 0.5:

Mean[RandomReal[1,10000]]

(RefLink[RandomReal, paclet:ref/RandomReal]) generates white noise:

ListLinePlot[Abs[Fourier[RandomReal[{-1,1},1000]]]]

OpenersExampleSection5(Spacer1)Neat Examples  (1)

Construct a surface from random heights:

ListPlot3D[Log[RandomReal[1,{50,50}]]]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[RandomVariate, paclet:ref/RandomVariate])  ▪  (RefLink[RandomInteger, paclet:ref/RandomInteger])  ▪  (RefLink[RandomComplex, paclet:ref/RandomComplex])  ▪  (RefLink[RandomChoice, paclet:ref/RandomChoice])  ▪  (RefLink[SeedRandom, paclet:ref/SeedRandom])  ▪  (RefLink[FindInstance, paclet:ref/FindInstance])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Pseudorandom Numbers, paclet:tutorial/PseudorandomNumbers])}, {▪(RefLinkPlain[Random Number Generation, paclet:tutorial/RandomNumberGenerationOverview])}, {▪(RefLinkPlain[Continuous Distributions, paclet:tutorial/ContinuousDistributions])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Random Number Generation, paclet:guide/RandomNumberGeneration])}, {▪(RefLinkPlain[Statistical Data Analysis, paclet:guide/Statistics])}, {▪(RefLinkPlain[Mathematical Functions, paclet:guide/MathematicalFunctions])}})}})

({{(Spacer1), ({{(Spacer1)Related Links}, {(WebLink[DocumentationFooterIconsRelatedLinks-EIWL.png(Spacer1)An Elementary Introduction to the Wolfram Language, https://www.wolfram.com/language/elementary-introduction/14-coordinates-and-graphics.html])(WebLink[: Coordinates and Graphics, https://www.wolfram.com/language/elementary-introduction/14-coordinates-and-graphics.html])}, {(WebLink[DocumentationFooterIconsRelatedLinks-EIWL.png(Spacer1)An Elementary Introduction to the Wolfram Language, https://www.wolfram.com/language/elementary-introduction/39-immediate-and-delayed-values.html])(WebLink[: Immediate and Delayed Values, https://www.wolfram.com/language/elementary-introduction/39-immediate-and-delayed-values.html])}})}})