Skip to content

rand.pcg32 #

Constants #

const seed_len = 4

struct PCG32RNG #

struct PCG32RNG {
	buffer.PRNGBuffer
mut:
	state u64 = u64(0x853c49e6748fea9b) ^ seed.time_seed_64()
	inc   u64 = u64(0xda3e39cb94b95bdb) ^ seed.time_seed_64()
}

PCG32RNG ported from http://www.pcg-random.org/download.html, https://github.com/imneme/pcg-c-basic/blob/master/pcg_basic.c, and https://github.com/imneme/pcg-c-basic/blob/master/pcg_basic.h

fn (PCG32RNG) seed #

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

seed seeds the PCG32RNG with 4 u32 values. The first 2 represent the 64-bit initial state as [lower 32 bits, higher 32 bits] The last 2 represent the 64-bit stream/step of the PRNG.

fn (PCG32RNG) u8 #

fn (mut rng PCG32RNG) u8() u8

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

fn (PCG32RNG) u16 #

fn (mut rng PCG32RNG) u16() u16

u16 returns a pseudorandom 16-bit unsigned integer (u16).

fn (PCG32RNG) u32 #

fn (mut rng PCG32RNG) u32() u32

u32 returns a pseudorandom unsigned u32.

fn (PCG32RNG) u64 #

fn (mut rng PCG32RNG) u64() u64

u64 returns a pseudorandom 64-bit unsigned u64.

fn (PCG32RNG) block_size #

fn (mut rng PCG32RNG) block_size() int

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

fn (PCG32RNG) free #

unsafe
fn (mut rng PCG32RNG) free()

free should be called when the generator is no longer needed