I ran your script and got 0.00693150741379456. I made a few minor changes and got 0.0069140819065811. Here's what I tried:
#!/usr/bin/perl use strict; use warnings; sub logfact { return gammln(shift(@_) + 1); } sub hypergeom { my ($n, $m, $N, $i) = @_; my $loghyp1 = logfact($m)+logfact($n)+logfact($N)+logfact($m+$n-$N) +; my $loghyp2 = logfact($i)+logfact($n-$i)+logfact($m+$i-$N)+logfact( +$N-$i)+logfact($m+$n); return exp($loghyp1 - $loghyp2); } sub gammln { my $xx = shift; my @cof = (76.180091729471457, -86.505320329416776, 24.014098240830911, -1.231739572450155, 0.12086509738661, -5.395239384953e-06); my $y = my $x = $xx; my $tmp = $x + 5.5; $tmp -= ($x + 0.5) * log($tmp); my $ser = 1.0000000001900149; foreach my $j (0 .. 5) { $ser += $cof[$j] / ++$y; } -$tmp + log(2.5066282746310007*$ser/$x); } print hypergeom(300,700,100,40),"\n";
I think that you'll need Math::GSL for Math::GSL::Randist. One other module that I like for getting gamma and log_gamma is Math::GammaFunction.

In reply to Re: Fast hypergeometric calculation in Perl by Khen1950fx
in thread Fast hypergeometric calculation in Perl by mrguy123

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.