package core:math/rand

Types

Rand ¶

Rand :: struct {
	state:     u64,
	inc:       u64,
	is_system: bool,
}

Constants

This section is empty.

Variables

This section is empty.

Procedures

choice ¶

choice :: proc "odin" (array: $T/[]$T, r: ^Rand = nil) -> (res: $T) {…}
 

Returns a random element from the given slice

create ¶

create :: proc "odin" (seed: u64) -> Rand {…}

exp_float64 ¶

exp_float64 :: proc "odin" (r: ^Rand = nil) -> f64 {…}
 

exp_float64 returns a exponential distribution in the range (0, max(f64)], with an exponential distribution who rate parameter is 1 (lambda) and whose mean is 1 (1/lambda).

To produce a distribution with a differetn rate parameter, divide the result by the desired rate parameter

"The Ziggurat Method for Generating Random Variables" Authors: George Marsaglia, Wai Wan Tsang Submitted: 2000-04-15. Published: 2000-10-02. https://www.jstatsoft.org/index.php/jss/article/view/v005i08/ziggurat.pdf [pdf] https://www.jstatsoft.org/article/view/v005i08 [web page]

float32 ¶

float32 :: proc "odin" (r: ^Rand = nil) -> f32 {…}
 

Uniform random distribution [0, 1)

float32_beta ¶

float32_beta :: proc "odin" (alpha, beta: f32, r: ^Rand = nil) -> f32 {…}
 

Beta Distribution

Required: alpha > 0 and beta > 0

Return values range between 0 and 1

float32_cauchy_lorentz ¶

float32_cauchy_lorentz :: proc "odin" (x_0, gamma: f32, r: ^Rand = nil) -> f32 {…}
 

Cauchy-Lorentz Distribution x_0 is the location, gamma is the scale where gamma > 0

float32_exponential ¶

float32_exponential :: proc "odin" (lambda: f32, r: ^Rand = nil) -> f32 {…}
 

Exponential Distribution lambda is 1.0/(desired mean). It should be non-zero. Return values range from 0 to positive infinity if lambda > 0 negative infinity to 0 if lambda <= 0

float32_gamma ¶

float32_gamma :: proc "odin" (alpha, beta: f32, r: ^Rand = nil) -> f32 {…}
 

Gamma Distribution (NOT THE GAMMA FUNCTION)

Required: alpha > 0 and beta > 0

math.pow(x, alpha-1) * math.exp(-x / beta) pdf(x) = -------------------------------------------- math.gamma(alpha) * math.pow(beta, alpha)

mean is alphabeta, variance is math.pow(alphabeta, 2)

float32_gompertz ¶

float32_gompertz :: proc "odin" (eta, b: f32, r: ^Rand = nil) -> f32 {…}
 

Gompertz Distribution eta is the shape, b is the scale Both eta and b must be > 0

float32_laplace ¶

float32_laplace :: proc "odin" (mean, b: f32, r: ^Rand = nil) -> f32 {…}
 

Laplace Distribution b is the scale where b > 0

float32_log_cauchy_lorentz ¶

float32_log_cauchy_lorentz :: proc "odin" (x_0, gamma: f32, r: ^Rand = nil) -> f32 {…}
 

Log Cauchy-Lorentz Distribution x_0 is the location, gamma is the scale where gamma > 0

float32_log_normal ¶

float32_log_normal :: proc "odin" (mean, stddev: f32, r: ^Rand = nil) -> f32 {…}
 

Log Normal Distribution

float32_normal ¶

float32_normal :: proc "odin" (mean, stddev: f32, r: ^Rand = nil) -> f32 {…}
 

Normal/Gaussian Distribution

float32_pareto ¶

float32_pareto :: proc "odin" (alpha, beta: f32, r: ^Rand = nil) -> f32 {…}
 

Pareto distribution, alpha is the shape parameter. https://wikipedia.org/wiki/Pareto_distribution

float32_range ¶

float32_range :: proc "odin" (lo, hi: f32, r: ^Rand = nil) -> f32 {…}

float32_triangular ¶

float32_triangular :: proc "odin" (lo, hi: f32, mode: runtime.Maybe(f32), r: ^Rand = nil) -> f32 {…}
 

Triangular Distribution See: http://wikipedia.org/wiki/Triangular_distribution

float32_von_mises ¶

float32_von_mises :: proc "odin" (mean_angle, kappa: f32, r: ^Rand = nil) -> f32 {…}
 

Circular Data (von Mises) Distribution mean_angle is the in mean angle between 0 and 2pi radians kappa is the concentration parameter which must be >= 0 When kappa is zero, the Distribution is a uniform Distribution over the range 0 to 2pi

float32_weibull ¶

float32_weibull :: proc "odin" (alpha, beta: f32, r: ^Rand = nil) -> f32 {…}
 

Weibull distribution, alpha is the scale parameter, beta is the shape parameter.

float64 ¶

float64 :: proc "odin" (r: ^Rand = nil) -> f64 {…}
 

Uniform random distribution [0, 1)

float64_beta ¶

float64_beta :: proc "odin" (alpha, beta: f64, r: ^Rand = nil) -> f64 {…}
 

Beta Distribution

Required: alpha > 0 and beta > 0

Return values range between 0 and 1

float64_cauchy_lorentz ¶

float64_cauchy_lorentz :: proc "odin" (x_0, gamma: f64, r: ^Rand = nil) -> f64 {…}
 

Cauchy-Lorentz Distribution x_0 is the location, gamma is the scale where gamma > 0

float64_exponential ¶

float64_exponential :: proc "odin" (lambda: f64, r: ^Rand = nil) -> f64 {…}
 

Exponential Distribution lambda is 1.0/(desired mean). It should be non-zero. Return values range from 0 to positive infinity if lambda > 0 negative infinity to 0 if lambda <= 0

float64_gamma ¶

float64_gamma :: proc "odin" (alpha, beta: f64, r: ^Rand = nil) -> f64 {…}
 

Gamma Distribution (NOT THE GAMMA FUNCTION)

Required: alpha > 0 and beta > 0

math.pow(x, alpha-1) * math.exp(-x / beta) pdf(x) = -------------------------------------------- math.gamma(alpha) * math.pow(beta, alpha)

mean is alphabeta, variance is math.pow(alphabeta, 2)

float64_gompertz ¶

float64_gompertz :: proc "odin" (eta, b: f64, r: ^Rand = nil) -> f64 {…}
 

Gompertz Distribution eta is the shape, b is the scale Both eta and b must be > 0

float64_laplace ¶

float64_laplace :: proc "odin" (mean, b: f64, r: ^Rand = nil) -> f64 {…}
 

Laplace Distribution b is the scale where b > 0

float64_log_cauchy_lorentz ¶

float64_log_cauchy_lorentz :: proc "odin" (x_0, gamma: f64, r: ^Rand = nil) -> f64 {…}
 

Log Cauchy-Lorentz Distribution x_0 is the location, gamma is the scale where gamma > 0

float64_log_normal ¶

float64_log_normal :: proc "odin" (mean, stddev: f64, r: ^Rand = nil) -> f64 {…}
 

Log Normal Distribution

float64_normal ¶

float64_normal :: proc "odin" (mean, stddev: f64, r: ^Rand = nil) -> f64 {…}
 

Normal/Gaussian Distribution

float64_pareto ¶

float64_pareto :: proc "odin" (alpha: f64, r: ^Rand = nil) -> f64 {…}
 

Pareto distribution, alpha is the shape parameter. https://wikipedia.org/wiki/Pareto_distribution

float64_range ¶

float64_range :: proc "odin" (lo, hi: f64, r: ^Rand = nil) -> f64 {…}

float64_triangular ¶

float64_triangular :: proc "odin" (lo, hi: f64, mode: runtime.Maybe(f64), r: ^Rand = nil) -> f64 {…}
 

Triangular Distribution See: http://wikipedia.org/wiki/Triangular_distribution

float64_von_mises ¶

float64_von_mises :: proc "odin" (mean_angle, kappa: f64, r: ^Rand = nil) -> f64 {…}
 

Circular Data (von Mises) Distribution mean_angle is the in mean angle between 0 and 2pi radians kappa is the concentration parameter which must be >= 0 When kappa is zero, the Distribution is a uniform Distribution over the range 0 to 2pi

float64_weibull ¶

float64_weibull :: proc "odin" (alpha, beta: f64, r: ^Rand = nil) -> f64 {…}
 

Weibull distribution, alpha is the scale parameter, beta is the shape parameter.

init ¶

init :: proc "odin" (r: ^Rand, seed: u64) {…}

init_as_system ¶

init_as_system :: proc "odin" (r: ^Rand = nil) {…}

int127 ¶

int127 :: proc "odin" (r: ^Rand = nil) -> i128 {…}

int127_max ¶

int127_max :: proc "odin" (n: i128, r: ^Rand = nil) -> i128 {…}

int31 ¶

int31 :: proc "odin" (r: ^Rand = nil) -> i32 {…}

int31_max ¶

int31_max :: proc "odin" (n: i32, r: ^Rand = nil) -> i32 {…}

int63 ¶

int63 :: proc "odin" (r: ^Rand = nil) -> i64 {…}

int63_max ¶

int63_max :: proc "odin" (n: i64, r: ^Rand = nil) -> i64 {…}

int_max ¶

int_max :: proc "odin" (n: int, r: ^Rand = nil) -> int {…}

norm_float64 ¶

norm_float64 :: proc "odin" (r: ^Rand = nil) -> f64 {…}
 

norm_float64 returns a normally distributed f64 in the range -max(f64) through +max(f64) inclusive, with a standard normal distribution with a mean of 0 and standard deviation of 1.

sample = norm_float64() * std_dev + mean

Normal distribution

"The Ziggurat Method for Generating Random Variables" Authors: George Marsaglia, Wai Wan Tsang Submitted: 2000-04-15. Published: 2000-10-02. https://www.jstatsoft.org/index.php/jss/article/view/v005i08/ziggurat.pdf [pdf] https://www.jstatsoft.org/article/view/v005i08 [web page]

perm ¶

perm :: proc "odin" (n: int, r: ^Rand = nil, allocator := context.allocator) -> []int {…}
 

perm returns a slice of n ints in a pseudo-random permutation of integers in the range [0, n)

read ¶

read :: proc "odin" (p: []u8, r: ^Rand = nil) -> (n: int) {…}

set_global_seed ¶

set_global_seed :: proc "odin" (seed: u64) {…}

shuffle ¶

shuffle :: proc "odin" (array: $T/[]$T, r: ^Rand = nil) {…}

uint128 ¶

uint128 :: proc "odin" (r: ^Rand = nil) -> u128 {…}

uint32 ¶

uint32 :: proc "odin" (r: ^Rand = nil) -> u32 {…}

uint64 ¶

uint64 :: proc "odin" (r: ^Rand = nil) -> u64 {…}

Procedure Groups

This section is empty.

Source Files

Generation Information

Generated with odin version dev-2023-03 (vendor "odin") Windows_amd64 @ 2023-03-29 21:09:05.377726500 +0000 UTC