Packages

builtin
cbindgen
core
core.alloc
core.alloc.arena
core.alloc.atomic
core.alloc.debug
core.alloc.fixed
core.alloc.gc
core.alloc.heap
core.alloc.log
core.alloc.memwatch
core.alloc.pool
core.alloc.ring
core.arg_parse
core.array
core.avl_tree
core.bucket_array
core.conv
core.crypto
core.crypto.keys
core.doc
core.encoding
core.encoding.base64
core.encoding.csv
core.encoding.hex
core.encoding.json
core.encoding.kdl
core.encoding.osad
core.encoding.utf8
core.encoding.xml
core.hash
core.hash.md5
core.hash.sha1
core.hash.sha256
core.heap
core.intrinsics
core.intrinsics.atomics
core.intrinsics.onyx
core.intrinsics.types
core.intrinsics.wasm
core.io
core.io.binary
core.iter
core.js
core.list
core.map
core.math
core.memory
core.misc
core.net
core.os
core.random
core.set
core.slice
core.string
core.sync
core.test
core.thread
core.time
main
runtime
runtime.info
runtime.platform
runtime.vars
simd

package core.random

Random
Random :: struct {
    seed: i64
}

The state of a random number generator.

Methods
Random.between
Random.between :: (self: &Random, lo: i32, hi: i32) -> i32

Generates a random 32-bit integer between lo and hi, inclusive.

Random.choice
Random.choice :: (self: &Random, a: [] $T) -> T

Returns a random element from a slice.

Random.float
Random.float :: (self: &Random, lo: f32, hi: f32) -> f32

Generates a random floating point number between lo and hi.

Random.int
Random.int :: (self: &Random) -> u32

Generates a random 32-bit integer.

Random.make
Random.make :: (seed: i64) -> Random

Creates a new random number generator.

An initial seed can be passed in, otherwise the current UNIX time is used.

Random.set_seed
Random.set_seed :: (self: &Random, s: u32) -> void
Random.set_seed :: (self: &Random, s: u64) -> void
Random.string
Random.string :: (self: &Random, bytes_long: u32, alpha_numeric: bool, allocator: Allocator) -> [] u8

Returns a random byte-array of length bytes_long.

If alpha_numeric is true, then the string will only consist of alpha-numeric characters.

between
between :: (lo: i32, hi: i32) -> i32

Generates a random integer, between lo and hi inclusively.

choice
choice :: (a: [] $T) -> #auto

Chooses a random element out of a slice.

float
float :: (lo: f32, hi: f32) -> f32

Generates a random floating point number.

int
int :: () -> u32

Generates a random integer.

set_seed
set_seed :: (s: u32) -> void
set_seed :: (s: u64) -> void

Sets the seed for the global random number generator.

string
string :: (bytes_long: u32, alpha_numeric: bool, allocator: Allocator) -> [] u8

Returns a random byte-array of length bytes_long.

If alpha_numeric is true, then the string will only consist of alpha-numeric characters.