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
Error PCALL
as
Creating habits v3, Lua
cases
123
ok
lua5.3: ...Desktop/rextester_linux_2.0/usercode/68368288/source.lua:166: unexpected symbol near '}'
VWPASSATPOLIZEI
Linear Regression Lua
Weight system (Will make a C# one soon too!)