Skip to content

Instantly share code, notes, and snippets.

@zundra
Last active March 8, 2021 21:53
Show Gist options
  • Save zundra/5edf9f1a3477d558dece31dd46059cd9 to your computer and use it in GitHub Desktop.
Save zundra/5edf9f1a3477d558dece31dd46059cd9 to your computer and use it in GitHub Desktop.
require 'openssl'
require 'awesome_print'
class TestRolls
def self.run(server_seed, client_seed, nonce)
rollcount = 0
wlmap = {
wins: {},
losses: {}
}
streakstate = 0
losestreak = 0
winstreak = 0
won_last_roll = false
while nonce < 100000 do
data = "#{client_seed}-#{nonce}"
digest = OpenSSL::HMAC.hexdigest("SHA512", server_seed, data)
chunks = digest.chars.each_slice(5).map(&:join)
roll = 0
chunks.each do |c|
roll = c.to_i(16)
break if roll < 999999
end
roll_result = roll % 100000
roll_nonce = nonce
if roll_result > 68764
won_last_roll = false
if streakstate == -1
losestreak = losestreak + 1
else
losestreak = 0
streakstate = -1
end
else
if streakstate == 1
won_last_roll = true
winstreak = winstreak + 1
else
winstreak = 0
streakstate = 1
end
end
if winstreak != 0
if wlmap[:wins].key?(winstreak) &&
wlmap[:wins][winstreak] += 1
elsif
wlmap[:wins][winstreak] = 1
end
end
if losestreak != 0
if wlmap[:losses].key?(losestreak) &&
wlmap[:losses][losestreak] += 1
elsif
wlmap[:losses][losestreak] = 1
end
end
nonce = nonce + 1
end
wlmap
end
end
wlmap = TestRolls.run("e65be50175f720f00427ab4923db68ac588b6cfec3d9ff61fa71947c1e9420ba", "quqnwnmoej", 0)
ap wlmap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment