#!/usr/bin/perl -w
use warnings;
use strict;
my $players = 1000; # Anzahl Spieler
my $p_precursor = 0.001; # Precursorwahrscheinlichkeit
my $num_tries = 25000; # Anzahl Versuche pro Spieler
my @player; # Precursor-Zähler pro Spieler
srand;
for (my $i=0; $i<$players; $i++) {
$player[$i] = 0;
# führe $num_tries Versuche durch
for (my $try=0; $try < $num_tries; $try++) {
my $is_precursor = rand() < $p_precursor;
$player[$i]++ if $is_precursor; # Zähler eins hoch, falls Precursor gedroppt
}
}
# gehe alle Spieler durch und zähle wie oft wieviele Precursor gedroppt wurden
my @precursor_count;
$precursor_count[$_]++ for @player;
my $sum = 0;
for (my $i=0; $i<scalar @precursor_count; $i++) {
print "" . ($precursor_count[$i] || 0) . " Spieler haben " . $i . " Precursor erhalten\n";
$sum += $precursor_count[$i] * $i if $precursor_count[$i];
}
print "Precursor insgesamt: $sum\n";