# MZT random number generator # # distribution: uniform # use r_univ() to get number from 0.0 to 1.0 package r_univ; use strict; use warnings; use Exporter; our @ISA=qw/Exporter/; our @EXPORT=qw/r_univ/; my @uu; my ($cc,$cd,$cm)=(362436.0/16777216.0, 7654321.0/16777216.0, 16777213.0/16777216.0); my ($ip,$jp)=(97,33); sub r_univ_init_rep($$$$){ my ($wi,$wj,$wk,$wl)=@_; my ($m,$t); foreach my $ii (0..96){ my ($s,$t)=(0,0.5); foreach my $jj (1..24){ $m=((($wi*$wj)%179)*$wk)%179; $wi=$wj; $wj=$wk; $wk=$m; $wl=(53*$wl+1)%169; $s+=$t if (($wl*$m)&63)>0x1f; $t*=0.5; $uu[$ii]=$s; } } } sub r_univ_init(){ srand(time()); my ($a,$b,$c,$d); do{ $a=1+rand()*178; $b=1+rand()*178; $c=1+rand()*178; $d=rand()*167; }while($a+$b+$c <= 3); r_univ_init_rep($a,$b,$c,$d); } sub r_univ(){ my $aux; $aux=$uu[$ip-1]-$uu[$jp-1]; ++$aux if($aux<0.0); $uu[$ip-1]=$aux; --$ip; $ip=97 unless $ip; --$jp; $jp=97 unless $jp; $cc-=$cd; $cc+=$cm if $cc<0.0; $aux-=$cc; ++$aux if $aux<0.0; return $aux; } r_univ_init(); 1;

In reply to MZT random number generator by js29a

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.