Created
August 27, 2018 15:11
-
-
Save KristofferC/c46af9ebbbfbf2a3bd5bd0b905c28b34 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Random | |
const ThreadRNG = MersenneTwister[] | |
@noinline init_thread_rng() = ThreadRNG[Threads.threadid()] = MersenneTwister(0) | |
@inline function thread_rng() | |
@inbounds begin | |
tid = Threads.threadid() | |
return isassigned(ThreadRNG, tid) ? ThreadRNG[tid] : init_thread_rng() | |
end | |
end | |
function ndx!(rng, N) | |
L = 0 | |
for n in 1:N | |
L += rand(rng, 1:6) | |
end | |
L | |
end | |
function gensum!(rng, seed) | |
Random.seed!(rng, seed) | |
ndx!(rng, 21) | |
end | |
function look() | |
resize!(ThreadRNG, Threads.nthreads()) | |
l = Threads.SpinLock() | |
Threads.@threads for i in 0x00000000:0x000FFFFF | |
rng = thread_rng() | |
s = gensum!(rng, i) | |
if (i | 0xFFF00000 == 0xFFF00000) | |
lock(l) | |
if (i | 0xFF000000 == 0xFF000000) | |
if (i | 0xF0000000 == 0xF0000000) | |
print(";") | |
end | |
print(",") | |
end | |
print(".") | |
unlock(l) | |
end | |
if (s == 126) | |
lock(l) | |
println("Found Legendary Character, seed ",i) | |
unlock(l) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment