# Uniform distribution on unit circle [duplicate]

This question already has an answer here:

I need a uniform distribution on the unit circle

(x; y) : x^2 + y^2 <= 1


with the density

f(x) = (2/Pi) Sqrt[1-x^2]


as a marginal distribution of pairs considered in point e.

I have no idea how to implement this and would appreciate any help.

## marked as duplicate by J. M. is away♦Nov 1 '17 at 11:05

• Please try to get a basic knowledge of the Mathematica syntax before asking – Dr. belisarius Oct 22 '14 at 12:16

For a uniform distribution on the unit circle you want the angle to be uniform on {0, 2Pi}

thetaDist = UniformDistribution[{0, 2 Pi}];

xDist = TransformedDistribution[
Cos[theta], theta \[Distributed] thetaDist];

Assuming[-1 < x < 1, PDF[xDist, x] // Simplify]


1/(Pi*Sqrt[1 - x^2])

Verifying that this is properly scaled

Integrate[PDF[xDist, x], {x, -1, 1}]


1

ListPlot[{Cos[#], Sin[#]} & /@
AspectRatio -> Automatic]


Alternatively,

ListPlot[
Flatten[
{{#, Sqrt[1 - #^2]}, {#, -Sqrt[1 - #^2]}} & /@
RandomVariate[xDist, 200],
1],
AspectRatio -> Automatic]


• @wolfies - the points on (as opposed to within) the unit circle are the points {Cos[theta], Sin[theta]} with theta uniformly distributed on {0, 2Pi}. The distribution of x is TransformedDistribution[ Cos[theta], theta \[Distributed] thetaDist] For a given x, the corresponding ys on the unit circle are just Sqrt[1-x^2] and -Sqrt[1-x^2]. Hence the mapping of {{#, Sqrt[1 - #^2]}, {#, -Sqrt[1 - #^2]}} onto the list of random x values. – Bob Hanlon Jun 29 '17 at 18:34

Since V10.2, there is RandomPoint:

pts = RandomPoint[Disk[], 2000];
Graphics[{
Circle[],
Red, Point@pts}]


(If the unit circle was desired, use Circle[] in place of Disk[].)

Just to provide other insights. RandomPoint as per MichaelE2 versus user defined probability distribution and confirmation desired marginal distribution:

pd = ProbabilityDistribution[
Piecewise[{{1/Pi, 0 < x^2 + y^2 <= 1}}], {x, -1, 1}, {y, -1, 1}]
md = MarginalDistribution[pd, 1]
PDF[md, x]
Show[Histogram3D[pts = RandomPoint[Disk[], 100000], Automatic, "PDF"],
Plot3D[PDF[pd, {x, y}], {x, -1, 1}, {y, -1, 1},
PlotStyle -> {Blue, Opacity[0.5]}, Mesh -> None]]
Show[Histogram[pts[[All, 1]], Automatic, "PDF"],
Plot[PDF[md, x], {x, -1, 1}]]


• BTW, WignerSemicircleDistribution[] is built-in. – J. M. is away Dec 19 '16 at 7:45
• @J.M. yes thank you. I just wanted to illustrate MarginalDistribution for user-defined probability distribution. Your comment is instructive (as usual). :) Best wishes for the festive season. – ubpdqn Dec 19 '16 at 8:09