Skip to content

rand.mt19937 #

Constants #

const seed_len = 2

struct MT19937RNG #

struct MT19937RNG {
	buffer.PRNGBuffer
mut:
	state []u64 = get_first_state(seed.time_seed_array(2))
	mti   int   = nn
}

MT19937RNG is generator that uses the Mersenne Twister algorithm with period 2^19937. NOTE: The RNG is not seeded when instantiated so remember to seed it before use.

fn (MT19937RNG) seed #

fn (mut rng MT19937RNG) seed(seed_data []u32)

seed sets the current random state based on seed_data. seed expects seed_data to be only two u32s in little-endian format as [lower, higher].

fn (MT19937RNG) u8 #

fn (mut rng MT19937RNG) u8() u8

byte returns a uniformly distributed pseudorandom 8-bit unsigned positive byte.

fn (MT19937RNG) u16 #

fn (mut rng MT19937RNG) u16() u16

u16 returns a pseudorandom 16bit int in range [0, 2¹⁶).

fn (MT19937RNG) u32 #

fn (mut rng MT19937RNG) u32() u32

u32 returns a pseudorandom 32bit int in range [0, 2³²).

fn (MT19937RNG) u64 #

fn (mut rng MT19937RNG) u64() u64

u64 returns a pseudorandom 64bit int in range [0, 2⁶⁴).

fn (MT19937RNG) block_size #

fn (mut rng MT19937RNG) block_size() int

block_size returns the number of bits that the RNG can produce in a single iteration.

fn (MT19937RNG) free #

unsafe
fn (mut rng MT19937RNG) free()

free should be called when the generator is no longer needed