Skip to content
This repository was archived by the owner on Aug 14, 2022. It is now read-only.

Latest commit

History

29 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

THIS MODULE HAS BEEN DEPRECATED AND V'S RAND MODULE SHOULD BE USED INSTEAD!

random

An all purpose random library written in V.

Features

  • All variate functions possible.
  • Generate random int and string with ease.
  • range functions for int and f32.
  • Array functions like shuffle, choose, sample etc.
  • Makes life easier sorta
  • Many more features coming soon!

Installation

  • Via git clone
    • git clone https://github.com/Delta456/random
  • Via v install
    • v install random
  • Via vpkg
    • vpkg install random

Docs

// 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) string

Usage

See math, random and string for usage.

Acknowledgments

I thank Python Software Foundation for their work on random library which helped me to port variate functions.

License

Licensed under MIT

About

An all purpose random library written in V.

Topics

Resources

Code of conduct

Stars

17 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages