Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.
|
|
geo
Posts:
38
Registered:
6/19/08
|
|
Re: KISS4691, a potentially top-ranked RNG.
Posted:
Jul 25, 2010 9:53 AM
|
|
On Jul 24, 11:34 pm, Gib Bogle <g.bo...@auckland.no.spam.ac.nz> wrote: > geo wrote: > > > Languages requiring signed integers should use equivalents > > of the same operations, except that the C statement: > > c=(t<x)+(x>>19); > > can be replaced by that language's version of > > if sign(x<<13+c)=sign(x) then c=sign(x)+(x>>19) > > else c=1-sign(t)+(x>>19) > > */ > > Hi George, > > I translated this into Fortran, and found that I get different results than with > C. I've tracked the difference into MWC(). The following Fortran code, with my > laborious comparison of two signed integers treating them as unsigned, gives > correct results. If I comment out the line > c = tLTx + SHIFTR(x,19) > and uncomment the following lines that implement your suggestion above to > compute c, I get different results. > > integer function MWC() > integer :: t, x, i > integer, save :: c = 0, j = 4691 > integer :: tLTx > > if (j < 4690) then > j = j + 1 > else > j = 0 > endif > x = Q(j) > t = SHIFTL(x,13) + c + x > if ((t >= 0 .and. x >= 0) .or. (t < 0 .and. x < 0)) then > if (t < x) then > tLTx = 1 > else > tLTx = 0 > endif > elseif (x < 0) then > tLTx = 1 > elseif (t < 0) then > tLTx = 0 > endif > > c = tLTx + SHIFTR(x,19) > > !if (sign(1,SHIFTL(x,13)+c) == sign(1,x)) then > ! c = sign(1,x) + SHIFTR(x,19) > !else > ! c = 1 - sign(1,t) + SHIFTR(x,19) > !endif > Q(j) = t > MWC = t > end function > > Is it the case that although your suggested workaround gives different results > from the C code in this case, it is still equivalent as a RNG? > > Cheers > Gib
Thanks very much for the Fortran version. I made a mistake in the comment on versions for signed integers. This:
Languages requiring signed integers should use equivalents of the same operations, except that the C statement: c=(t<x)+(x>>19); can be replaced by that language's version of if sign(x<<13+c)=sign(x) then c=sign(x)+(x>>19) else c=1-sign(t)+(x>>19)
should have been:
Languages requiring signed integers should use equivalents of the same operations, except that the C statement: c=(t<x)+(x>>19); can be replaced by that language's version of if sign(x<<13+c)=sign(x) then c=sign(x)+(x>>19) else c=1-sign(x<<13+c)+(x>>19)
Sorry for that error.
I still like inline functions in Fortan, so would tend to define isign(x)=ishft(x,-31) and m=ishft(x,13)+c if(isign(m).eq.isign(x)) then c=isign(x)+ishft(x,-19) else c=1-isign(m)+ishft(x,-19) and Q[j]=m+x
If calculating the carry c of the MWC operation fails to fix that extra increment properly, then rather than a systematic expansion, in reverse order, 32 bits at a time, of the binary representation of j/(1893*2^150112-1) for some j determined by the random seeds, we will be jumping around in that expansion, and we can't be sure that the period will still be the order of b=2^32 for the prime p=1893*b^4196-1.
gm
|
|
|
|