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
Surface Area of things (Incomplete)
Convert MySQL 'framed' table into CSV
Roots without the math library in Lua
cumulative probability
hack
Fixed
VERSION
test3
Replace all substring in string
Lua recursion with function