Skip to content

Instantly share code, notes, and snippets.

@simonbyrne
Created June 8, 2016 13:45
Show Gist options
  • Save simonbyrne/51c1f29205c8d3374030d28b932f0f00 to your computer and use it in GitHub Desktop.
Save simonbyrne/51c1f29205c8d3374030d28b932f0f00 to your computer and use it in GitHub Desktop.
@inline function rotr(x,y)
s = sizeof(x) << 3
(x >> (y % s)) | (x << (-y % s))
end
function foo(state, n)
s = sizeof(state) << 3
t = trailing_zeros(s)-1 # log2(s)-1
p1 = (s>>1 + t)>>1
p2 = s>>1 - t
p3 = s-t
y = UInt64(0)
for i = 1:n
x = rotr(
(((state >> p1) $ state) >> p2) % UInt32,
(state >> p3) % UInt32
)
state = state * 0x5851f42d4c957f2d + 0x000000000000006d
y += x
end
return y
end
@time foo(0x185706b82c2e03f8, 10_000_000)
using RNG.PCG
r = PermutedCongruentialGenerator(PCGStateSetseq, PCG_XSH_RR, UInt64)
function bar(r,n)
y = UInt64(0)
for i = 1:n
y += UInt64(rand(r,UInt32))
end
y
end
srand(r, (42 % UInt64, 54 % UInt64))
@time bar(r,10_000_000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment