Pseudo-random numbers/PCG32: Difference between revisions

Content added Content deleted
(add REXX (for the "fun" of it)
m (→‎{{header|REXX}}: corrected dshift, added ishift)
Line 1,314: Line 1,314:
DON'T use Rexx, however, for this type of problem unless you take the time spent
DON'T use Rexx, however, for this type of problem unless you take the time spent
for some Java coffies!
for some Java coffies!
<lang rexx>
<lang rexx>Numeric Digits 40
Numeric Digits 40
Call time 'R'
N = 6364136223846793005
N = 6364136223846793005
state = x2d('853c49e6748fea9b',16)
state = x2d('853c49e6748fea9b',16)
Line 1,336: Line 1,334:
Say format(z,2) ':' format(cnt.z,5)
Say format(z,2) ':' format(cnt.z,5)
End
End
Say time('E')
Exit
Exit


Line 1,372: Line 1,369:
oldx2=b2x(oldb2)
oldx2=b2x(oldb2)
rotx=x2d(substr(oldx2,9),8)
rotx=x2d(substr(oldx2,9),8)
t1=dshift(shifted,rotx,'L')
t1=ishift(shifted,rotx,'L')
t2=x2d(xneg(d2x(rotx,8)),8)
t2=x2d(xneg(d2x(rotx,8)),8)
t3=t2+1
t3=t2+1
Line 1,509: Line 1,506:
Else Do
Else Do
If o='L' Then Do
If o='L' Then Do
If left(nb,1)=1 Then
nb=copies(0,32)substr(nb,33)
rb=left(copies('0',s)nb,length(nb))
rb=left(copies('0',s)nb,length(nb))
rx=b2x(rb)
rx=b2x(rb)
ry=left(rx,8)
r=x2d(rx,16)
r=x2d(rx,16)
End
End
Line 1,520: Line 1,514:
rx=b2x(rb)
rx=b2x(rb)
r=x2d(rx,16)
r=x2d(rx,16)
End
End
Return r

ishift: Procedure
/**********************************************************************
* Implement the shift operations for an int variable
* r = dshift(int,shift[,mode]) >> Mode='L' logical right shift
* >>> Mode='A' arithmetic right shift
* << xhift<0 left shift
********************************************`*************************/
Parse Upper Arg n,s,o
Numeric Digits 40
If o='' Then o='L'
nx=d2x(n,8)
nb=x2b(nx)
If s<0 Then Do
s=abs(s)
rb=substr(nb,s+1)||copies('0',s)
rx=b2x(rb)
r=x2d(rx,8)
End
Else Do
If o='L' Then Do
rb=left(copies('0',s)nb,length(nb))
rx=b2x(rb)
r=x2d(rx,8)
End
Else Do
rb=left(copies(left(nb,1),s)nb,length(nb))
rx=b2x(rb)
r=x2d(rx,8)
End
End
End
End