Probabilistic choice: Difference between revisions

Content added Content deleted
m (→‎{{header|Ring}}: Remove vanity tags)
(→‎{{header|Perl 6}}: added .race for concurrency, now requires atomic ops)
Line 2,156: Line 2,156:


=={{header|Perl 6}}==
=={{header|Perl 6}}==
{{works with|rakudo|2015-10-20}}
{{works with|Rakudo|2018.10}}
<lang perl6>constant TRIALS = 1e6;
<lang perl6>constant TRIALS = 1e6;
Line 2,164: Line 2,164:
constant @cP = [\+] @P;
constant @cP = [\+] @P;
my @results;
my atomicint @results[+@event];
@results[ @cP.first: { $_ > once rand }, :k ]++ xx TRIALS;
(^TRIALS).race.map: { @results[ @cP.first: { $_ > once rand }, :k ]++; }

say 'Event Occurred Expected Difference';
say 'Event Occurred Expected Difference';
for ^@results {
for ^@results {