in reply to Loaded die

Rather than brute force iteration, you could always simulate:

#! perl -slw use strict; use Data::Dump qw[ pp ]; use List::Util qw[ sum ]; use Math::Random::MT qw[ rand ]; my $throws = 5; my $sides = 5; my @probs = ( 0.05, 0.1, 0.2, 0.3, 0.35 ); my @values = ( 1, 5, 7, 13, 17 ); my @lookup = map{ ( $values[ $_ ] ) x ( $probs[ $_ ] * 100 ); } 0 .. $#values; our $MIN //= 60; our $RUNS //= 1e5; my $moreThanMin = 0; for ( 1 .. $RUNS ) { my $total = sum map{ $lookup[ rand( scalar @lookup ) ] } 1 .. $thr +ows; ++$moreThanMin if $total > $MIN; } printf "Probability based on $RUNS simulations: %.3f%%", $moreThanMin / $RUNS * 100; __END__ c:\test>895892 -RUNS=1e6 Probability based on 1e6 simulations: 48.752%

It won't save time on small die, but on the larger ones you can decide how much time you want to spend to get closer and closer to the answer.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: Loaded die
by Microcebus (Beadle) on Mar 28, 2011 at 14:20 UTC
    You are right. I thought about this option but in my special case, I have to calculate possibilities like 1/10^100. Hence I would have to do more than 10^100 simulations...
      I have to calculate possibilities like 1/10^100.

      Hm. Odds that small are so close to zero as to be meaningless.

      There are estimated to be 10^80 atoms in the universe. If one of them had gone missing (or an extra one had materialised into existance) at some point after matter crystallised out of the big bang, the affect the absence or presence of that one atom would have had on the form of the universe would be undetectable at any scale.

      And the affect that a 1/10^100 change in probability will have (on anything) is 100 million trillion times less significant.

      To try and put that into perspective. If a casino dice had 1/10^100 bias, it would undetectable by any mechanism. I would guess that every single dice ever produced has been, is, and always will be biased billions of times more significantly. A single missing electron from the face of the dice will bias it far more significantly than that.

      Indeed, the bias of every dice ever made probably varies by bllions of times more than that, second by second, due to moisture absorption, evaporation or radioactive decay.

      If every human being that ever existed, threw every dice that ever existed, once every microsecond, for their entire lives and you managed to record every single throw, you would not be able to detect if such a rare event had occurred or not.

      So what is the point of knowing such probabilities? Even knowing that they are not zero is useless information.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        Of course, my problem is not the die itself. My goal is to asses gene clusters.
        Imagine 10000 different genes. Each gene can have the values from 1, 10 or 100 (lets say it depends on their size). So I have:
        500 genes with value 1
        2000 genes with value 10
        7500 genes with value 100
        If I look at a certain gene cluster comprising 100 genes with an average value of 2.8 I want to calculate the possibility, that this occures by chance to make a declaration about the clusters exceptionality.
        And in this context, possibilities are often <1/10^100.
        I compare different clusters compairing the log10 of the reciprocal possibility.