1
0
Fork
You've already forked xoshiro256starstar.lua
0
Xoshiro256** PRNG generate algorithm written in Lua.
  • Lua 100%
Find a file
2026年03月16日 01:32:30 +08:00
LICENSE Add license and test 2026年03月16日 01:30:06 +08:00
README.md typo 2026年03月16日 01:32:30 +08:00
test.lua Add license and test 2026年03月16日 01:30:06 +08:00
xoshiro256starstar.lua Add license and test 2026年03月16日 01:30:06 +08:00

xoshiro256** written in Lua

This repo reimplemented the xoshiro256** random generation algorithm in Lua, which is the algorithm used by math.random of original Lua 5.4.

The code is just a "translated version" of source code of math.random to get behavior that exactly same as standard math.random and math.randomseed function.

Why do this?

Standard math.random doesn't allow us create individual random generators, since it uses a global random state which stores in its upvalues.

This work presents a random generator constructor with following features:

  • You can construct many random generators with their own random states
  • Random generation algorithm is totally same as the standard math.random

Usage

local rand = require "xoshiro256starstar"
-- random state is stored in this variable. And it will be initialized using random seed
local gen = rand()
-- you can reset the seed just like `math.randomseed`
gen:randomseed(1234)
-- And the `random` method is just same as `math.random` too
gen:random(1000) -- generate random number within [1, 1000].
gen = rand(1234) -- you can set seed in the constructor too.

Todos

  • I didn't take 32-bit architectures into consideration
  • English is not my first language so there could be lots of typo or grammar mistakes in the code and doc.