Although I can't install the module Algorithm::Loops, I believe if I'm following correctly (after reading up on this module on CPAN) that the sums you have set up are:
0 + 0 = 0 0 + 1 = 1 0 + 2 = 2 1 + 0 = 1 1 + 1 = 2 1 + 2 = 3 2 + 0 = 2 2 + 1 = 3 2 + 2 = 4
Then, when you calculate the p value for the sucessful combination (2 + 2 is the only one to equal 4), you've mutiplied the probability of a 2 (= .7) times the probability for another 2 and get the answer (.49). If there had been other combs that equaled 4, their probability would have been calculated and added to the .49.

I guess I am wondering if the sum to be gotten was 2, for example, then 3 cases would qualify with your algorithm.

0 + 2 = 2 1 + 1 = 2 2 + 0 = 2
But, do you really want to count (0, 2) *and* (2, 0) because they are the same elements (from the original array), only one is the reverse of the other. Also, do you want to include the same item added to itself (1 + 1)?

The numbers you are generating now are also known as the cross product of n sets. Perhaps you just want to test all the possible combinations instead?

0 + 1 = 1 0 + 2 = 2 1 + 2 = 3

As far as your code scaling up, it depends on how large the number of trials. If you use the cross product, with 10,000 numbers there will be 10,000 * 10,000 trials. On the other hand, if you tested the combinations there would be 10,000 * 9,999 / 2 trials - half as many.

Chris


In reply to Re: Probability sum of random variables by Cristoforo
in thread Probability sum of random variables by FFRANK

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.