Constrained random points on a circle: Difference between revisions

→‎{{header|Perl}}: added version with plain-text output
m (→‎{{header|Perl 6}}: added sample output)
(→‎{{header|Perl}}: added version with plain-text output)
Line 2,159:
 
=={{header|Perl}}==
===Graphical output===
<lang perl>my @points;
while (@points < 100) {
Line 2,183 ⟶ 2,184:
 
Randomly generates points and reject ones not in the ring. Writes an EPS file.
 
===Plain-text output===
<lang perl>@range = -15..16;
 
for $x (@range) {
for $y (@range) {
$radius = sqrt $x**2 + $y**2;
push @points, [$x,$y] if 10 <= $radius and $radius <= 15
}
}
 
push @sample, @points[int rand @points] for 1..100;
push @matrix, ' ' x @range for 1..@range;
substr $matrix[15+$$_[1]], 15+$$_[0], 1, '*' for @sample;
print join(' ', split '', $_) . "\n" for @matrix;</lang>
{{out}}
<pre> * * *
* * *
* * *
* *
* * * *
* *
* * * *
* * *
* *
* *
* * * * * * *
*
 
* * *
*
* * * *
* *
* * *
* * *
* * * *
* * *
* * * *
* *
* *
* * * *
* * * * *
* * * * *
* *
*</pre>
 
=={{header|Perl 6}}==
2,392

edits