user
Given a mapping between items and their required probability of occurrence, generate a million items *randomly* subject to the given probabilities and compare the target probability of occurrence versus the generated values.

The total of all the probabilities should equal one. (Because floating point arithmetic is involved, this is subject to rounding errors).

Use the following mapping to test your programs:

```
aleph   1/5.0
beth    1/6.0
gimel   1/7.0
daleth  1/8.0
he      1/9.0
waw     1/10.0
zayin   1/11.0
heth    1759/27720 # adjusted so that probabilities add to 1
```

Related task

* Random number generator (device)
assistant
(formerly Perl 6)

**Works with**: Rakudo version 2018.10

```
constant TRIALS = 1e6;
 
constant @event = <aleph beth gimel daleth he waw zayin heth>;
 
constant @P = flat (1 X/ 5 .. 11), 1759/27720;
constant @cP = [\+] @P;
 
my atomicint @results[+@event];
(^TRIALS).race.map: { @results[ @cP.first: { $_ > once rand }, :k ]⚛++; }

say  'Event    Occurred Expected  Difference';
for ^@results {
    my ($occurred, $expected) = @results[$_], @P[$_] * TRIALS;
    printf "%-9s%8.0f%9.1f%12.1f\n",
            @event[$_],
                $occurred,
                     $expected,
                          abs $occurred - $expected;
}

```

Output:

```
Event    Occurred Expected  Difference
aleph      200369 200000.0       369.0
beth       167005 166666.7       338.3
gimel      142690 142857.1       167.1
daleth     125061 125000.0        61.0
he         110563 111111.1       548.1
waw        100214 100000.0       214.0
zayin       90617  90909.1       292.1
heth        63481  63456.0        25.0
```