Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- `mt` : mersenne twisted pseudorandom number array
- `index` : index of the current `mt` position
- others : indexing global functions for faster performance
- ]]
- local mt, index, band, bor, bxor, lshift, rshift = {}, 0, bit.band, bit.bor, bit.bxor, bit.lshift, bit.rshift
- --[[
- initializes `mt` with custom seed or current time
- ]]
- local init_rand = function(s)
- if s == nil then
- s = os.time()
- end
- mt[0] = band(s, 0xffffffff)
- for index = 1, 623 do
- mt[index] = band(0x6c078965 * bxor(mt[index - 1], rshift(mt[index - 1], 30)) + index, 0xffffffff)
- end
- end
- --[[
- extracts random number from `mt` with tampering
- ]]
- local rand = function()
- local matrix, y = {0, 0x9908b0df}
- if index == 0 then
- init_rand()
- for i = 0, 623 do
- y = bor(band(mt[i], 0x80000000), band(mt[(i + 1) % 624], 0x7ffffff))
- mt[i] = bxor(mt[(i + 397) % 624], rshift(y, 1), matrix[band(y, 1) + 1])
- end
- end
- index = (index + 1) % 624
- y = mt[index]
- --[[ tampering ]]
- y = bxor(y, rshift(y, 11))
- y = band(bxor(y, lshift(y, 7), 0x9d2c5680))
- y = band(bxor(y, lshift(y, 15), 0xefc60000))
- y = bxor(y, rshift(y, 18))
- return y % 0xffffffff
- end
- for _ = 1, 10000000 do
- rand()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement