THIS MODULE HAS BEEN DEPRECATED AND V'S RAND MODULE SHOULD BE USED INSTEAD!
An all purpose random library written in V.
- All variate functions possible.
- Generate random
intandstringwith ease. - range functions for
intandf32. - Array functions like
shuffle,choose,sampleetc. - Makes life easier sorta
- Many more features coming soon!
- Via
git clonegit clone https://github.com/Delta456/random
- Via
v installv install random
- Via
vpkgvpkg install random
// struct for `triangular()`structTriangular {
mut:
low f32=1.0
high f32=1.0
mode int=1
}
// struct for `int_range()`structIntRange {
start int
stop int
step int=1
}
// struct for `float_range()`structFloatRange {
start f32
stop f32
step f32=1.0
}
// normal_variate is the normal distribution where mu is the // mean, and stigma is the standard deviationfnnormal_variate(mu, stigma f32) f32// expo_variate is the expovariate distribution where lambda is // 1.0 divided by the desired mean. It should be nonzero. // return values range from 0 to positive infinity if lambda is // positive else negativefnexpo_variate(lambda f32) f32// weibull distribution where alpha is the scale parameter and // beta is the shape parameterfnweibull_variate(alpha, beta f32) f32// lognorm_variate is the log nomral distribution If you take // the natural logarithm of this distribution, you'll get a // normal distribution with mean mu and standard deviation //sigma. mu can have any value, and sigma must be greater than// zerofnlognorm_variate(mu, stigma f32) f32// gamma_distribution is the gamma distribution conditions on the parameters are alpha > 0 and beta > 0.// conditions on the parameters are alpha > 0 and beta > 0.// The probability distribution function is:// math.pow(x, (alpha - 1)) * math.exp(-x / beta)// pdf(x) = --------------------------------------// math.gamma(alpha) * math.pow(beta, alpha)fngamma_variate(alpha, beta f32) f32// beta_variate is the beta distribution parameters alpha > 0 // and beta > 0 return values range between 0 and 1fnbeta_variate(alpha, beta f32) f32// pareto_variate is pareto distribution. alpha is the shape // paramter.fnpareto_variate(alpha f32) f32// vommeises_variate is the circular data distribution// where mu is the mean angle, expressed in radians between 0 and 2*pi, and// kappa is the concentration parameter, which must be greater than or// equal to zero. If kappa is equal to zero, this distribution reduces// to a uniform random angle over the range 0 to 2*pi// mu: mean angle (in radians between 0 and 2*pi)// kappa: concentration parameter kappa (>= 0)// if kappa == 0 then generate uniform random anglefnvommeises_variate(mu, kappa f32) f32// triangular is the triangular distribution. continuous // distribution bounded by given lower and upper limits, and // having a given mode value in-betweenfntriangular(mut tri Triangular) f32// uniform returns a random number between the range [a, b) or // [a, b] depending on roundingfnuniform(a, b f32) f32// int_range returns a random int between the specified rangefnint_range(range IntRange) int// float_range returns a random float upon the given rangefnfloat_range(range FloatRange) f32// numeric returns a number with n digits longfnnumeric(n int) int// bool returns a random boolfnbool() bool// shuffle returns the new shuffled arrayfnshuffle<T>(arr []T) []T
// sample returns the new k-sized array// no_repetitions must be true when no repetitions are needed// else it must be falsefnsample<T>(arr []T, k int) []T
// choose returns a random element from the arrayfnchoose<T>(arr []T) T
// string returns a random string of n lengthfnstring(n int) string// string_alpha returns an alpha string of n lengthfnstring_alpha(n int) stringSee math, random and string for usage.
I thank Python Software Foundation for their work on random library which helped me to port variate functions.
Licensed under MIT