Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Basic Lehmer RNG implementation using closures
--lua 5.3 local function lehmer(s) local seed if s == nil then seed = os.time() else seed = assert(tonumber(s), "seed is not a number") assert(s == s and s ~= math.huge, "seed cannot be nan or inf") seed = math.fmod(math.floor(s), 2^31-1) if seed <= 0 then seed = seed + 2^31-2 end end return function() seed = math.fmod(seed*16807, 2^31-1) return math.tointeger(seed) -- on Lua 5.1, return seed directly instead end end local rng = lehmer() for _ = 1, 1000 do print(rng()) end
run
|
edit
|
history
|
help
1
The Pyramid in the two-dimensional array made of random stones - Lua
help with lua number input
Percentage Calculator (Subscribe to Madflag19)
hij
ok
gdgdf
VWPASSATPOLIZEI
VERSION
Security keygen
Goalless DRAWS