rand.sys #

struct SysRNG #

struct SysRNG {
mut:
	seed u32 = util.time_seed_32()
}

fn (SysRNG) seed #

fn (mut r SysRNG) seed(seed_data []u32)

r.seed() sets the seed of the accepting SysRNG to the given data.

fn (SysRNG) default_rand #

fn (r SysRNG) default_rand() int

r.default_rand() exposes the default behavior of the system's RNG (equivalent to calling C.rand()). Recommended for testing/comparison b/w V and other languages using libc and not for regular use. This is also a one-off feature of SysRNG, similar to the global seed situation. Other generators will not have this.

fn (SysRNG) u32 #

fn (r SysRNG) u32() u32

r.u32() returns a pseudorandom u32 value less than 2^32

fn (SysRNG) u64 #

fn (r SysRNG) u64() u64

r.u64() returns a pseudorandom u64 value less than 2^64

fn (SysRNG) u32n #

fn (r SysRNG) u32n(max u32) u32

r.u32n(max) returns a pseudorandom u32 value that is guaranteed to be less than max

fn (SysRNG) u64n #

fn (r SysRNG) u64n(max u64) u64

r.u64n(max) returns a pseudorandom u64 value that is guaranteed to be less than max

fn (SysRNG) u32_in_range #

fn (r SysRNG) u32_in_range(min u32, max u32) u32

r.u32n(min, max) returns a pseudorandom u32 value that is guaranteed to be in [min, max)

fn (SysRNG) u64_in_range #

fn (r SysRNG) u64_in_range(min u64, max u64) u64

r.u64n(min, max) returns a pseudorandom u64 value that is guaranteed to be in [min, max)

fn (SysRNG) int #

fn (r SysRNG) int() int

r.int() returns a pseudorandom 32-bit int (which may be negative)

fn (SysRNG) i64 #

fn (r SysRNG) i64() i64

r.i64() returns a pseudorandom 64-bit i64 (which may be negative)

fn (SysRNG) int31 #

fn (r SysRNG) int31() int

r.int31() returns a pseudorandom 31-bit int which is non-negative

fn (SysRNG) int63 #

fn (r SysRNG) int63() i64

r.int63() returns a pseudorandom 63-bit int which is non-negative

fn (SysRNG) intn #

fn (r SysRNG) intn(max int) int

r.intn(max) returns a pseudorandom int that lies in [0, max)

fn (SysRNG) i64n #

fn (r SysRNG) i64n(max i64) i64

r.i64n(max) returns a pseudorandom i64 that lies in [0, max)

fn (SysRNG) int_in_range #

fn (r SysRNG) int_in_range(min int, max int) int

r.int_in_range(min, max) returns a pseudorandom int that lies in [min, max)

fn (SysRNG) i64_in_range #

fn (r SysRNG) i64_in_range(min i64, max i64) i64

r.i64_in_range(min, max) returns a pseudorandom i64 that lies in [min, max)

fn (SysRNG) f32 #

fn (r SysRNG) f32() f32

r.f32() returns a pseudorandom f32 value between 0.0 (inclusive) and 1.0 (exclusive) i.e [0, 1)

fn (SysRNG) f64 #

fn (r SysRNG) f64() f64

r.f64() returns a pseudorandom f64 value between 0.0 (inclusive) and 1.0 (exclusive) i.e [0, 1)

fn (SysRNG) f32n #

fn (r SysRNG) f32n(max f32) f32

r.f32n() returns a pseudorandom f32 value in [0, max)

fn (SysRNG) f64n #

fn (r SysRNG) f64n(max f64) f64

r.f64n() returns a pseudorandom f64 value in [0, max)

fn (SysRNG) f32_in_range #

fn (r SysRNG) f32_in_range(min f32, max f32) f32

r.f32_in_range(min, max) returns a pseudorandom f32 that lies in [min, max)

fn (SysRNG) f64_in_range #

fn (r SysRNG) f64_in_range(min f64, max f64) f64

r.i64_in_range(min, max) returns a pseudorandom i64 that lies in [min, max)