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}} |
||
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 |
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: |
|||
⚫ | |||
⚫ | |||
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}}== |