lua bindings for https://github.com/MersenneTwister-Lab/SFMT
luarocks install sfmt
generates a pseudo-random 32bit unsigned integer.
Parameters
max:integer
: a maximum value. (default: maximum value oflua_Integer
)min:integer
: a minimum value. (default:0
)
Returns
v:integer
: a pseudo-random 32bit unsigned integer.
Example
local sfmt = require('sfmt')
local v = sfmt.rand32()
print(v) -- 600594209
generates a pseudo-random 64bit unsigned integer.
Parameters
max:integer
: a maximum value. (default: maximum value oflua_Integer
)min:integer
: a minimum value. (default:0
)
Returns
v:integer
: a pseudo-random 64bit unsigned integer.
Example
local sfmt = require('sfmt')
local v = sfmt.rand64()
print(v) -- 8.6473937871833e+17
generates a pseudo-random number on closed interval [0,1]. (0 <= v <= 1)
Parameters
max:number
: a maximum value. (default:1
)min:number
: a minimum value. (default:0
)
Returns
v:number
: a pseudo-random number.
Example
local sfmt = require('sfmt')
local v = sfmt.real1()
print(v) -- 0.017114813676364
generates a pseudo-random number on half-open interval [0,1). (0 <= v < 1)
Parameters
max:number
: a maximum value. (default:1
)min:number
: a minimum value. (default:0
)
Returns
v:number
: a pseudo-random number.
Example
local sfmt = require('sfmt')
local v = sfmt.real2()
print(v) -- 0.35999271506444
generates a pseudo-random number on open interval (0,1). (0 < v < 1)
Parameters
max:number
: a maximum value. (default:1
)min:number
: a minimum value. (default:0
)
Returns
v:number
: a pseudo-random number.
Example
local sfmt = require('sfmt')
local v = sfmt.real3()
print(v) -- 0.017114813676364
generates a pseudo-random number on half-open interval [0,1) with 53-bit resolution. (0 <= v < 1)
Parameters
max:number
: a maximum value. (default:1
)min:number
: a minimum value. (default:0
)
Returns
v:number
: a pseudo-random number with 53-bit resolution.
Example
local sfmt = require('sfmt')
local v = sfmt.res53()
print(v) -- 0.35999271506444
generates a pseudo-random number on half-open interval [0,1) with 53-bit resolution using two 32bit integers.
Parameters
max:number
: a maximum value. (default:1
)min:number
: a minimum value. (default:0
)
Returns
v:number
: a pseudo-random number with 53-bit resolution.
Example
local sfmt = require('sfmt')
local v = sfmt.res53mix()
print(v) -- 0.35999271506444
initializes the default generator with an unsigned 32bit integer seed value.
Parameters
seed:integer
: seed value....:integer
: additional seed values.
NOTE
If no seed value is passed, a default seeds are automatically generated as follows:
// create 4 seed values
for (int i = 0; i < 4; i++) {
struct timespec t = {0};
clock_gettime(CLOCK_MONOTONIC, &t);
lua_pushinteger(L, t.tv_nsec);
}
// initialize the default generator using the above seed values
// ...
creates an independent random number generator object.
Parameters
seed:integer
: seed value....:integer
: additional seed values.
Returns
s:sfmt
: an independent random number generator object. this object has the same methods as the default generator.s:init()
: same assfmt.init()
s:rand32()
: same assfmt.rand32()
s:rand64()
: same assfmt.rand64()
s:real1()
: same assfmt.real1()
s:real2()
: same assfmt.real2()
s:real3()
: same assfmt.real3()
s:res53()
: same assfmt.res53()
s:res53mix()
: same assfmt.res53mix()
Example
local sfmt = require('sfmt')
local s = sfmt.new()
print(s) -- sfmt: 0x12b80fc38
print(s:rand32()) -- 1587595272
The MIT License (MIT)