Constrained random points on a circle: Difference between revisions

Content added Content deleted
m (→‎{{header|Perl 6}}: formatting, omit useless semicolons)
(Attempted a clearer task description)
Line 1: Line 1:
{{task|Probability and statistics}}
{{task|Probability and statistics}}
The task is to generate a stream of 100 uniformly distributed random points (x,y integer pairs) that lie in a circular disc at 10 to 15 units from its center; and then display/plot them to show a fuzzy circle. The actual number plotted may be less than 100, because some will overlap.
Generate 100 <x,y> coordinate pairs such that x and y are integers sampled from the uniform distribution with the condition that <math>10 \leq \sqrt{ x^2 + y^2 } \leq 15 </math>. Then display/plot them. The outcome should be a "fuzzy" circle. The actual number of points plotted may be less than 100, given that some pairs may be generated more than once.


There are several possible approaches, depending on your language. One is simply to generate random pairs of integers and filter out those that don't satisfy the equation
There are several possible approaches to accomplish this. Here are two possible algorithms.


1) Generate random pairs of integers and filter out those that don't satisfy this condition:
: <math>10 \leq \sqrt{ x^2 + y^2 } \leq 15</math>


:<math>10 \leq \sqrt{ x^2 + y^2 } \leq 15 </math>.
Another is to precalculate the set of all possible points (there are 404 of them) and select from this set. Yet another is to use real-valued polar coordinates then snap to integer Cartesian coordinates. I'm sure there are others.

2) Precalculate the set of all possible points (there are 404 of them) and select randomly from this set.


=={{header|D}}==
=={{header|D}}==