({{, (RefLink[RandomPoint, paclet:ref/RandomPoint])[reg] 
gives a pseudorandom point uniformly distributed in the region reg.}, {, (RefLink[RandomPoint, paclet:ref/RandomPoint])[reg,n]
gives a list of n pseudorandom points uniformly distributed in the region reg.}, {, (RefLink[RandomPoint, paclet:ref/RandomPoint])[reg,{(Subscript[n, 1]),(Subscript[n, 2]),…}]
gives an (Subscript[n, 1])× (Subscript[n, 2])×… array of pseudorandom points.}, {, (RefLink[RandomPoint, paclet:ref/RandomPoint])[reg,…,{{(Subscript[x, min]),(Subscript[x, max])},…}]
restricts to the bounds [(Subscript[x, min]),(Subscript[x, max])]×⋯.}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[RandomPoint, paclet:ref/RandomPoint]) can generate random points for any (RefLink[RegionQ, paclet:ref/RegionQ]) region that is also (RefLink[ConstantRegionQ, paclet:ref/ConstantRegionQ]).

(RefLink[RandomPoint, paclet:ref/RandomPoint]) will generate points uniformly in the region reg.

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

With the setting (RefLink[WorkingPrecision, paclet:ref/WorkingPrecision])->p, random numbers of precision p will be generated.

OpenersPrimaryExamplesSection(Spacer1)Examples  (55)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

Generate a list of points in a unit disk:

pts=RandomPoint[Disk[],5000];

Graphics[{PointSize[Tiny],Point[pts]}]

Generate multiple lists of points on a unit circle:

pl=RandomPoint[Circle[],{3,100}];

Table[Graphics[Point[pts]],{pts,pl}]

Generate a list of points in a standard cylinder:

pts=RandomPoint[Cylinder[],10^4];

Graphics3D[{PointSize[Tiny],Point[pts]},Boxed->False]

OpenersExampleSection1(Spacer1)Scope  (22)

OpenersExampleSubsection0(Spacer1)Basic Uses  (5)

Generate a point in a unit ball region:

ℛ=Ball[];

pt=RandomPoint[ℛ]

RegionMember[ℛ,pt]

Generate a list of points for a triangle region:

ℛ=Triangle[{{0,0},{1,1},{2,0}}];

pts=RandomPoint[ℛ,1000];

Graphics[{ℛ,Red,PointSize[Tiny],Point[pts]}]

Generate multiple lists of points for a unit disk region:

ℛ=Disk[];

pl=RandomPoint[ℛ,{3,20}];

Table[Graphics[{ℛ,Red,Point[pts]}],{pts,pl}]

Generate points on an unbounded region within given bounds:

ℛ=HalfPlane[{{0,0},{1,1}},{0,1}];

pts=RandomPoint[ℛ,10^4,{{0,1},{0,1}}];

The random points are restricted to [0,1]×[0,1]:

Graphics[{LightBlue,ℛ,Red,PointSize[Tiny],Point[pts]},Frame->True,PlotRangePadding->0.1]

Generate points on an unbounded region within given bounds in (ℝ^3):

ℛ=ConicHullRegion[{{0,0,0}},{{-1,1,1},{1,1,1},{-1,1,0},{1,1,0}}];

pts=RandomPoint[ℛ,10^4,{{-1,1},{-1,1},{-1,1}}];

Graphics3D[{{Opacity[0.5],ℛ},{Blue,PointSize[Tiny],Point[pts]}},Axes->True,PlotRange->{{-2,2},{0,2},{-1,2}}]

OpenersExampleSubsection1(Spacer1)Special Regions  (6)

Regions in (ℝ^1):

RandomPoint[Point[{{1},{2},{3}}]]

RandomPoint[Interval[{1,5}],5]

Regions in (ℝ^2):

RandomPoint[Point[{{1,1},{2,2},{3,3}}]]

RandomPoint[Line[{{0,0},{1,1}}]]

RandomPoint[Disk[{1,2},{3,4}]]

Visualize region points in (ℝ^2):

pts=RandomPoint[Circle[],300];

Graphics[Point[pts]]

Regions in (ℝ^3):

RandomPoint[Point[{{1,1,1},{2,2,2},{3,3,3}}]]

RandomPoint[Line[{{1,2,3},{4,5,6}}]]

RandomPoint[Polygon[{{1,0,0},{0,1,0},{0,0,1}}]]

RandomPoint[Cone[{{0,0,0},{1,1,1}},1/2]]

Visualize region points in (ℝ^3):

ℛ=Tetrahedron[];

pts=RandomPoint[ℛ,300];

Graphics3D[{{Opacity[0.2],ℛ},{Green,Sphere[pts,0.02]}},Boxed->False]

Regions in (ℝ^n):

RandomPoint[Point[{{1,1,1,1},{2,2,2,2},{3,3,3,3}}]]

RandomPoint[Simplex[{{1,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1}}]]

RandomPoint[Cuboid[{1,2,3,4,5},{6,7,8,9,10}]]

RandomPoint[Ball[{0,0,0,0,0,0,0},8]]

OpenersExampleSubsection2(Spacer1)Formula Regions  (3)

Implicit regions:

RandomPoint[ImplicitRegion[(x^2)+(y^2)≤1,{x,y}]]

RandomPoint[ImplicitRegion[(x^2)+(y^2)≤1,{x,y,{z,0,2}}]]

Visualize region points in (ℝ^2):

ℛ=ImplicitRegion[x^2-2y^2<=1,{{x,-3,3},{y,-4,4}}];

pts=RandomPoint[ℛ,10^4,{{-3,3},{-4,4}}];

Graphics[{PointSize[Tiny],Point[pts]}]

Parametric regions:

ℛ=ParametricRegion[{{s,(1+t) s^2-t},-1≤s≤1&&0≤t≤1},{s,t}];

pts=RandomPoint[ℛ,5000];

Graphics[{PointSize[Tiny],Point[pts]}]

OpenersExampleSubsection3(Spacer1)Mesh Regions  (4)

(RefLink[MeshRegion, paclet:ref/MeshRegion]) in 2D:

ℛ=DelaunayMesh[RandomReal[8,{50,2}]];

pts=RandomPoint[ℛ,2000];

Show[ℛ,Graphics[{Red,PointSize[Tiny],Point[pts]}]]

In 3D:

ℛ=DelaunayMesh[RandomReal[8,{50,3}]];

pts=RandomPoint[ℛ,200];

Show[HighlightMesh[RegionBoundary[ℛ],Style[2,Opacity[0.1]]],Graphics3D[{Green,Sphere[pts,0.2]}]]

(RefLink[BoundaryMeshRegion, paclet:ref/BoundaryMeshRegion]) in 2D:

ℛ=ConvexHullMesh[RandomReal[8,{50,2}]];

pts=RandomPoint[ℛ,2000];

Show[ℛ,Graphics[{Red,PointSize[Tiny],Point[pts]}]]

(RefLink[BoundaryMeshRegion, paclet:ref/BoundaryMeshRegion]) in 3D:

ℛ=ConvexHullMesh[RandomReal[8,{50,3}]];

pts=RandomPoint[ℛ,200];

Show[HighlightMesh[RegionBoundary[ℛ],Style[2,Opacity[0.1]]],Graphics3D[{Green,Sphere[pts,0.2]}]]

OpenersExampleSubsection4(Spacer1)Derived Regions  (4)

(RefLink[RegionIntersection, paclet:ref/RegionIntersection]) of two regions:

ℛ=RegionIntersection[Disk[{0, 0}, 1],Disk[{0,1}, 1]];

pts=RandomPoint[ℛ,5000];

Graphics[{PointSize[Tiny],Point[pts]}]

(RefLink[RegionUnion, paclet:ref/RegionUnion]) of mixed-dimensional regions:

ℛ=RegionUnion[Circle[{1, 0}, 1],Disk[{0, 0}, 1]];

DiscretizeRegion[ℛ]

Points are generated for the maximum dimensional component:

pts=RandomPoint[ℛ,5000];

Graphics[{PointSize[Tiny],Point[pts]}]

(RefLink[TransformedRegion, paclet:ref/TransformedRegion]):

ℛ=TransformedRegion[Disk[{0,0},1],ShearingTransform[Pi/4,{1,0},{0,1}]];

pts=RandomPoint[ℛ,3000];

Graphics[{PointSize[Tiny],Point[pts]}]

(RefLink[RegionBoundary, paclet:ref/RegionBoundary]):

ℛ=RegionBoundary[Disk[{0,0},1]];
DiscretizeRegion[ℛ]

pts=RandomPoint[ℛ,100];

Graphics[Point[pts]]

OpenersExampleSection3(Spacer1)Applications  (24)

OpenersExampleSubsection5(Spacer1)2D Galleries  (9)

Generate a list of uniform random unit vectors in (ℝ^2):

v=RandomPoint[Sphere[{0,0},1],200];

Graphics[Table[Arrow[{{0,0},p}],{p,v}]]

Visualize a parametric heart curve:

ℛ=ParametricRegion[
{(4 Sin[t]^3)/5,1/20 (13 Cos[t]-5 Cos[2 t]-2 Cos[3 t]-Cos[4 t])},{{t,0,2 π}}];

pts=RandomPoint[ℛ,10^3,{{-1,1},{-1,1}}];

Graphics[{PointSize[Tiny],Point[pts]}]

Parametric butterfly curve:

ℛ=ParametricRegion[{1/5 (E^Cos[t]-2 Cos[4 t]+Sin[t/12]^5) Sin[t],1/5 Cos[t] (E^Cos[t]-2 Cos[4 t]+Sin[t/12]^5)-1/6},{{t,0,100}}];

pts=RandomPoint[ℛ,5000,{{-1,1},{-1,1}}];

Graphics[{PointSize[Tiny],Point[pts]}]

Implicit trifolium curve:

ℛ=ImplicitRegion[x^3-3 x y^2+(x^2+y^2)^2==0,{x,y}];

pts=RandomPoint[ℛ,10^3,{{-1,1},{-1,1}}];

Graphics[{PointSize[Tiny],Point[pts]}]

(RefLink[Graphics, paclet:ref/Graphics]) scene:

p=RandomReal[1,{20,2}];
g=Graphics[{BSplineCurve[p],Line[p]}];

pts=RandomPoint[DiscretizeGraphics[g],10^4];

Graphics[{PointSize[Tiny],Point[pts]}]

Implicit Lissajous region:

ℛ=ImplicitRegion[-1+(((-1+18 (x^2)-48 (x^4)+32 (x^6)))^2)+(((-1+18 (y^2)-48 (y^4)+32 (y^6)))^2) ≤0,{x,y}];

pts=RandomPoint[ℛ,10^4];

Graphics[{PointSize[Tiny],Point[pts]}]

Mixed implicit and parametric region:

ℛ=ParametricRegion[{{s,s t},s^2+t^2≤1},{s,t}];

pts=RandomPoint[ℛ,10^4];

Graphics[{PointSize[Tiny],Point[pts]}]

Country polygon:

ℛ=DiscretizeGraphics[CountryData["Austria","Polygon"]];

pts=RandomPoint[ℛ,5000];

Graphics[{PointSize[Tiny],Point[pts]}]

(RefLink[Text, paclet:ref/Text]) primitive:

t=Text[Style["π",Bold]];

mr=DiscretizeGraphics[t,_Text,MaxCellMeasure->0.1];

pts=RandomPoint[mr,3000];

Graphics[{PointSize[Tiny],Point[pts]}]

OpenersExampleSubsection6(Spacer1)3D Galleries  (6)

Generate a list of uniform random unit vectors in (ℝ^3):

v=RandomPoint[Sphere[{0,0,0},1],200];

Graphics3D[Table[Arrow[{{0,0,0},p}],{p,v}],Boxed->False]

Parametric helix curve:

ℛ=ParametricRegion[{Cos[t],Sin[t],t/16},{{t,0,9π}}];

pts=RandomPoint[ℛ,10^3,{{-1,1},{-1,1},{0,2}}];

Graphics3D[{PointSize[Tiny],Point[pts]},Boxed->False]

Implicit Viviani's curve:

ℛ=ImplicitRegion[(((-1+x))^2)+(y^2)==1&&(x^2)+(y^2)+(z^2)==4,{x,y,z}];

pts=RandomPoint[ℛ,10^3];

Graphics3D[{PointSize[Tiny],Point[pts]},Boxed->False]

Parametric torus surface:

ℛ=ParametricRegion[{(3+Cos[v])Cos[u],(3+Cos[v])Sin[u],Sin[v]},{{u,0,2Pi},{v,0,2Pi}}];

pts=RandomPoint[ℛ,4000,{{-4,4},{-4,4},{-1,1}}];

Graphics3D[{PointSize[Tiny],Point[pts]},Boxed->False]

Implicit eight solid:

ℛ=ImplicitRegion[4 z^4+9 (x^2+y^2-4 z^2)≤1,{x,y,z}];

pts=RandomPoint[ℛ,4000];

Graphics3D[{PointSize[Tiny],Point[pts]},Boxed->False]

(RefLink[Graphics3D, paclet:ref/Graphics3D]) scene:

p=Table[{i,j,RandomReal[{-1,1}]},{i,5},{j,5}];
g=Graphics3D[{BSplineSurface[p],Sphere[#,0.1]&/@p}];

pts=RandomPoint[DiscretizeGraphics[g],5000];

Graphics3D[{PointSize[Tiny],Point[pts]},Boxed->False]

OpenersExampleSubsection7(Spacer1)Monte Carlo Methods  (2)

Perform Monte Carlo integration to estimate the area of a unit disk:

ℛ=Disk[{0,0},1];
Graphics[{LightBlue,EdgeForm[Gray],ℛ}]

Get the region bounds:

boundingBox=Cuboid@@Transpose[RegionBounds[ℛ]]

Uniformly sample over the bounding box of the region:

pts=RandomPoint[boundingBox,10^4];

col=RegionMember[ℛ,pts]/.{False->Gray,True->Red};
Graphics[{ℛ,PointSize[Tiny],{col,Point/@pts}\[Transpose]}]

Count the number of samples inside the region:

inside=Count[RegionMember[ℛ,pts],True]

Get the ratio of samples inside the region to the total number of sample points:

ratio=N[(inside/(Length[pts]))]

Get the bounding area:

area=Area[boundingBox]

Get the approximate area of the region:

area*ratio

Visualize the Minkowski sum (orange) of two regions:

r1=Annulus[{9,0},{3,4}];
r2=RegularPolygon[{0,10},2,3];

p1=RandomPoint[r1,10^5];
p2=RandomPoint[r2,10^5];

Sum of points from two regions gives points of the Minkowski sum region:

msum=p1+p2;

Graphics[{{Blue,r1},{Brown,r2},{Orange,PointSize[Tiny],Point[msum]}}]

OpenersExampleSubsection8(Spacer1)Region Relations  (3)

Compute an approximate bounding box for a region from random samples. The resulting bounding will be a subset of the true bounding box:

ℛ=Polygon[{{0,0},{2,-1},{1,0},{2,1}}];

pts=RandomPoint[ℛ,10^3];

CoordinateBounds[pts]

Compare with its region bounds:

RegionBounds[ℛ]

Show that a region is not a subset of another:

{disk,square}={Disk[{1,1/2},1/2],Rectangle[]};

g=Graphics[{Opacity[0.5],{Green,square},{Blue,disk}}]

Check if any point from a set of random points in the disk are not in the square:

mf=RegionMember[square];

pts=RandomPoint[disk,10^3];

AllTrue[pts,mf]

Visualize the random points in the disk that are not in the square:

Show[g,Graphics[{Red,PointSize[Tiny],Point[Select[pts,Not@*mf]]}]]

Determine that two regions are not equal:

{disk,square}={Disk[{1/2,1/2},1/2],Rectangle[]};

Graphics[{Opacity[0.5],{Green,square},{Blue,disk}}]

Check if any point from a set of random points in the disk is not in the square, or vice versa:

possibleSubregion[r1_,r2_]:=AllTrue[RandomPoint[r1,10^3],RegionMember[r2]];

possibleSubregion[disk,square]

possibleSubregion[square,disk]

OpenersExampleSubsection9(Spacer1)Approximate Convexity  (2)

Determine that a region is not convex by sampling, and show that there is a convex combination of the samples that is not a member of the original region:

ℛ=Polygon[{{0,0},{2,-1},{1,0},{2,1}}];

Generate pairwise convex combinations of random points within the region:

rp=RandomPoint[ℛ,10];

pairs=Line/@Subsets[rp,{2}];

If a point on a pairwise convex combination is not in the region, then the region is not convex:

AllTrue[pairs,AllTrue[RandomPoint[#,10^2],RegionMember[ℛ]]&]

Graphics[{ℛ,Red,pairs}]

Alternatively generate and test points in a convex hull of points:

ch=ConvexHullMesh[RandomPoint[ℛ,30]];

AllTrue[RandomPoint[ch,10^4],RegionMember[ℛ]]

Show[{Graphics[{ℛ}],HighlightMesh[ch,Style[2, Opacity[0.5]]]}]

Compute the approximate convex hull of a region from random points within the region:

ℛ=ImplicitRegion[x^3-3x y^2+(x^2+y^2)^2<0,{x,y}];

pts=RandomPoint[ℛ,3000];

cm=ConvexHullMesh[pts];

Show[cm,Graphics[{Red,PointSize[Tiny],Point[pts]}]]

OpenersExampleSubsection10(Spacer1)Nearest and Farthest Points  (2)

Find an approximate nearest point in a region by sampling the region and computing the nearest point to the samples. This gives an upper bound for the distance to the region:

ℛ=Triangle[{{0,0},{1,1},{2,0}}];

pt={2,1};

Find the nearest point from a set of random points in the region:

rp=RandomPoint[ℛ,10^3];

np=First[Nearest[rp,pt]]

Graphics[{LightGray,ℛ,Gray,Point[rp],PointSize[Medium],Black,Point[pt],Red,Point[np],Dashed,Line[{pt,np}]}]

Compare the resulting distance to the true minimum distance to the region:

apprDist=EuclideanDistance[pt,np]

exactDist=RegionDistance[ℛ,pt]//N

exactDist<apprDist

Define a function that finds an approximate farthest point in a region:

approximateFarthest[reg_,pt_]:=First[Nearest[RandomPoint[reg,10^4],pt,DistanceFunction->(-Norm[#1-#2]&)]]

Find the farthest point on a region from a given point:

ℛ=Triangle[{{0,0},{1,1},{2,0}}];

pt={2,1};

fp=approximateFarthest[ℛ,{2,1}]

Graphics[{Point[pt],LightGray,ℛ,Red,Point[fp],Dashed,Line[{pt,fp}]}]

region=DiscretizeGraphics[CountryData["Mexico","Polygon"],ImageSize->Medium]

ppp[region_,intensity_,n_]:=Module[{nlist,pts},nlist=RandomVariate[PoissonDistribution[intensity RegionMeasure[region]],n];
pts=RandomPoint[region,Total[nlist]];
nlist=Accumulate[nlist];
nlist=Transpose[{Prepend[Most[nlist]+1,1],nlist}];
Table[Take[pts,ind],{ind,nlist}]]

intensity=0.5;
sample=ppp[region,intensity,1];

Show[region,Graphics[{Black,Point@@sample}]]

samples=ppp[region,intensity,10^4];
counts=Length/@samples;

PearsonChiSquareTest[counts,PoissonDistribution[intensity RegionMeasure[region]],"TestDataTable"]

disk1=Disk[{-107,28},1.5];
Show[region,Graphics[{Red,disk1}]]

memberfun1=RegionMember[disk1];
counts1=Table[Total[Boole[memberfun1[pts]]],{pts,samples}];

PearsonChiSquareTest[counts1,PoissonDistribution[intensity RegionMeasure[disk1]],"TestDataTable"]

disk2=Disk[{-100,20},1.3];
Show[region,Graphics[{Red,disk1,Blue,disk2}]]

memberfun2=RegionMember[disk2];
counts2=Table[Total[Boole[memberfun2[pts]]],{pts,samples}];

SpearmanRankTest[counts1,counts2,"TestDataTable"]

OpenersExampleSection4(Spacer1)Properties & Relations  (6)

(RefLink[RandomPoint, paclet:ref/RandomPoint]) will generate points with uniform density:

ℛ=Disk[];

pts=RandomPoint[ℛ,10^5];

Histogram3D[pts]

Choosing random coordinate points from a region of points:

pts=RandomReal[1,{1000,2}];

ℛ=Point[pts];

rp=RandomPoint[ℛ,10^4];

Corresponds to (RefLink[RandomChoice, paclet:ref/RandomChoice]) of coordinate points:

rc=RandomChoice[pts,10^4];

Histogram3D/@{rp,rc}

Choosing random points from a (RefLink[Cuboid, paclet:ref/Cuboid]) region:

bounds={{-1,1},{-1,1},{-1,1}};

ℛ=Cuboid@@Transpose[bounds];

rp=RandomPoint[ℛ,5000];

Corresponds to (RefLink[RandomVariate, paclet:ref/RandomVariate]) of a (RefLink[UniformDistribution, paclet:ref/UniformDistribution]):

rv=RandomVariate[UniformDistribution[bounds],5000];

Table[Graphics3D[{PointSize[Tiny],Point[p]},Boxed->False],{p,{rp,rv}}]

Choosing random points from a (RefLink[Disk, paclet:ref/Disk]) region:

{a,r}={1,3};

ℛ=Disk[{a,0},r];

rp=RandomPoint[ℛ,10^4];

Corresponds to (RefLink[RandomVariate, paclet:ref/RandomVariate]) of a (RefLink[WignerSemicircleDistribution, paclet:ref/WignerSemicircleDistribution]):

rv=RandomVariate[WignerSemicircleDistribution[a,r],10^4];

Histogram/@{rp[[All,1]],rv}

Choosing random coordinate points from a (RefLink[Triangle, paclet:ref/Triangle]) region:

{min,max,mode}={-1,2,1};

ℛ=Triangle[{{min,0},{max,0},{mode,1}}];

rp=RandomPoint[ℛ,10^4];

Corresponds to (RefLink[RandomVariate, paclet:ref/RandomVariate]) of a (RefLink[TriangularDistribution, paclet:ref/TriangularDistribution]):

rv=RandomVariate[TriangularDistribution[{min,max},mode],10^4];

Histogram/@{rp[[All,1]],rv}

(RefLink[FindInstance, paclet:ref/FindInstance]) can generate exact instances for special and formula regions:

FindInstance[{x,y,z}∈Sphere[{1,1,1},1/2],{x,y,z}]

However, instances are not uniform:

ℛ=ImplicitRegion[(x^2)+(y^2)≤1,{x,y}];

fi={x,y}/.FindInstance[{x,y}∈ℛ,{x,y},Reals,10^3];

rp=RandomPoint[ℛ,10^3];

Histogram3D/@{fi,rp}

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[RegionMember, paclet:ref/RegionMember])  ▪  (RefLink[RegionQ, paclet:ref/RegionQ])  ▪  (RefLink[ConstantRegionQ, paclet:ref/ConstantRegionQ])  ▪  (RefLink[RandomVariate, paclet:ref/RandomVariate])  ▪  (RefLink[RandomGeoPosition, paclet:ref/RandomGeoPosition])  ▪  (RefLink[FindInstance, paclet:ref/FindInstance])  ▪  (RefLink[RegionDistance, paclet:ref/RegionDistance])  ▪  (RefLink[SpherePoints, paclet:ref/SpherePoints])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Region Properties and Measures, paclet:guide/GeometricPropertiesAndMeasures])}, {▪(RefLinkPlain[Random Number Generation, paclet:guide/RandomNumberGeneration])}, {▪(RefLinkPlain[Polygons, paclet:guide/Polygons])}, {▪(RefLinkPlain[Polyhedra, paclet:guide/Polyhedra])}})}})