comp.lang.ada
 help / color / mirror / Atom feed
From: "robin" <robin51@dodo.com.au>
Subject: Re: Implementing the KISS4691 RNG
Date: Wed, 8 Sep 2010 13:15:27 +1000
Date: 2010-09-08T13:15:27+10:00	[thread overview]
Message-ID: <4c8753d5$0$45649$c30e37c6@exi-reader.telstra.net> (raw)
In-Reply-To: 93b6ca11-f4ae-4598-98f8-9a10be69ca3a@j18g2000yqd.googlegroups.com

"geo" <gmarsaglia@gmail.com> wrote in message news:93b6ca11-f4ae-4598-98f8-9a10be69ca3a@j18g2000yqd.googlegroups.com...
|
| For signed integers, flip the
| sign bits so that t<x becomes (t^m)<(x^m) or equivalents.
| (C versions using signed integers should also avoid the
| problem of right shifts, replacing (x>>19) by
| ((unsigned)x>>19) or ((unsigned)xs>>17) in the XS component.)

In the case of signed integers, both  t<c  AND  t<x
must have their sign bits flipped, not just  t<x.

Thus, the signed version in PL/I is:

(NOSIZE, NOFOFL):
RNG: PROCEDURE OPTIONS (MAIN, REORDER);

   declare (xs initial (521288629), xcng initial (362436069),
            Q(0:4690) ) static fixed binary (31);

MWC: procedure () returns (fixed binary (31));
   declare (t,x,i) fixed binary (31);
   declare (c initial (0), j initial (4691) ) fixed binary (31) static;
   declare m fixed binary (31) static initial ((isll(1,31)));

   if j < hbound(Q,1) then j = j + 1; else j = 0;
   x = Q(j); t = isll(x,13) + c;
   if ieor(t,m) < ieor(c,m) then
      do; c = isrl(x, 19) + 1; t = t + x; end;
   else
      do; t = t + x; c = isrl(x, 19) + (ieor(t,m) < ieor(x,m)); end;
   Q(j)=t;
   return (t);
end MWC;

CNG: procedure returns (fixed binary (31));
  xcng=bin(69069)*xcng+bin(123);
  return (xcng);
end CNG;

XXS: procedure returns (fixed binary (31));
   xs = ieor (xs, isll(xs, 13) );
   xs = ieor (xs, isrl(xs, 17) );
   xs = ieor (xs, isll(xs,  5) );
   return (xs);
end XXS;

KISS: procedure returns (fixed binary (31));
   return ( MWC()+CNG+XXS );
end KISS;

   declare (i,x) fixed binary (31);
   declare y fixed decimal (10);

   Q = CNG + XXS; /* Initialize: */
   do i = 1 to 1000000000; x=MWC(); end;
   put skip edit (" Expected MWC result = 3740121002", 'computed =', x)
      (a, skip, x(12), a, f(11));
   y = iand(x, 2147483647);
   if x < 0 then y = y + 2147483648;
   put skip edit (y) (x(11), f(22)); put skip;
   do i = 1 to 1000000000; x=KISS; end;
   put skip edit ("Expected KISS result = 2224631993", 'computed =', x)
      (a, skip, x(12), a, f(11));
   y = iand(x, 2147483647);
   if x < 0 then y = y + 2147483648;
   put skip edit (y) (x(11), f(22));

end RNG;






      parent reply	other threads:[~2010-09-08  3:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <93b6ca11-f4ae-4598-98f8-9a10be69ca3a@j18g2000yqd.googlegroups.com>
2010-09-07 16:51 ` Implementing the KISS4691 RNG robin
2010-09-08  3:15 ` robin [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox