Various random and noise functions.
Namespace defines various random number generators (RNGs), different types of random functions, sequence generators and noise functions.
You can use a selection of various RNGs defined in Apache Commons Math library.
Currently supported RNGs:
:jdk
- default java.util.Random:mersenne
- MersenneTwister:isaac
- ISAAC:well512a
, :well1024a
, :well19937a
, :well19937c
, :well44497a
, :well44497b
- several WELL variantsTo create your RNG use rng
multimethod. Pass RNG name and (optional) seed. Returned RNG is equipped with RNGProto
protocol with methods: [[irandom]], [[lrandom]], [[frandom]] [[drandom]], [[grandom]], [[brandom]] which return random primitive value with given RNG.
(let [rng (rng :isaac 1337)]
(irandom rng))
For conveniency default RNG (:mesenne
) with following functions are created: irand
, lrand
, frand
, drand
, grand
, brand
.
Each prefix denotes returned type:
Check individual function for parameters description.
Couple of functions to generate sequences of numbers or vectors.
You can generate sequence of double
, [[Vec2]], [[Vec3]] or [[Vec4]] types. Just pass the size to creator function.
To create generator call sequence-generator
with generator name and vector size [1,4].
Following generators are available:
:halton
- Halton low-discrepancy sequence; range [0,1]:sobol
- Sobol low-discrepancy sequence; range [0,1]:sphere
- uniformly random distributed on unit sphere:gaussian
- gaussian distributed (mean=0, stddev=1):default
- uniformly random; range:[0,1]After creation you get function equivalent to repeatedly
.
List of continuous noise functions (1d, 2d and 3d):
:value
- value noise:gradient
- gradient noise (improved Ken Perlin version):simplex
- simplex noiseFirst two (:value
and :gradient
) can use 4 different interpolation types: :none
, :linear
, :hermite
(cubic) and :quintic
.
All can be used as into:
single-noise
fbm-noise
billow-noise
ridgedmulti-noise
Noise creation requires detailed configuration which is simple map of following keys:
:seed
- seed as integer:noise-type
- type of noise: :value
, :gradient
(default), :simplex
:interpolation
- type of interpolation (for value and gradient): :none
, :linear
, :hermite
(default) or :quintic
:octaves
- number of octaves for combined noise (like FBM), default: 6:lacunarity
- scaling factor for combined noise, default: 2.00:gain
- amplitude scaling factor for combined noise, default: 0.5:normalize?
- should be normalized to [0,1]
range (true, default) or to [-1,1]
range (false)For usage convenience 3 ready to use functions are prepared. Return is normalized to [0,1]
range:
noise
- Perlin Noise (gradient noise, 6 octaves, quintic interpolation)vnoise
- Value Noise (as in Processing, 6 octaves, hermite interpolation)simplex
- Simpled Noise (6 octaves)discrete-noise
is a 1d or 2d hash function for given integers. Returns double from [0,1]
range.
Various real and integer distributions. See DistributionProto
and RNGProto
for functions.
To create distribution call distribution
multimethod with name as a keyword and map as parameters.
Various random and noise functions. Namespace defines various random number generators (RNGs), different types of random functions, sequence generators and noise functions. #### RNGs You can use a selection of various RNGs defined in [Apache Commons Math](http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math3/random/package-summary.html) library. Currently supported RNGs: * `:jdk` - default java.util.Random * `:mersenne` - MersenneTwister * `:isaac` - ISAAC * `:well512a`, `:well1024a`, `:well19937a`, `:well19937c`, `:well44497a`, `:well44497b` - several WELL variants To create your RNG use [[rng]] multimethod. Pass RNG name and (optional) seed. Returned RNG is equipped with [[RNGProto]] protocol with methods: [[irandom]], [[lrandom]], [[frandom]] [[drandom]], [[grandom]], [[brandom]] which return random primitive value with given RNG. ``` (let [rng (rng :isaac 1337)] (irandom rng)) ``` For conveniency default RNG (`:mesenne`) with following functions are created: [[irand]], [[lrand]], [[frand]], [[drand]], [[grand]], [[brand]]. Each prefix denotes returned type: * i - int * l - long * f - float * d - double * g - gaussian (double) * b - boolean Check individual function for parameters description. #### Random Vector Sequences Couple of functions to generate sequences of numbers or vectors. You can generate sequence of `double`, [[Vec2]], [[Vec3]] or [[Vec4]] types. Just pass the size to creator function. To create generator call [[sequence-generator]] with generator name and vector size [1,4]. Following generators are available: * `:halton` - Halton low-discrepancy sequence; range [0,1] * `:sobol` - Sobol low-discrepancy sequence; range [0,1] * `:sphere` - uniformly random distributed on unit sphere * `:gaussian` - gaussian distributed (mean=0, stddev=1) * `:default` - uniformly random; range:[0,1] After creation you get function equivalent to `repeatedly`. #### Noise List of continuous noise functions (1d, 2d and 3d): * `:value` - value noise * `:gradient` - gradient noise (improved Ken Perlin version) * `:simplex` - simplex noise First two (`:value` and `:gradient`) can use 4 different interpolation types: `:none`, `:linear`, `:hermite` (cubic) and `:quintic`. All can be used as into: * Noise - pure noise value, create with [[single-noise]] * FBM - fractal brownian motion, create with [[fbm-noise]] * Billow - billow noise, [[billow-noise]] * RidgedMulti - ridged multi, [[ridgedmulti-noise]] Noise creation requires detailed configuration which is simple map of following keys: * `:seed` - seed as integer * `:noise-type` - type of noise: `:value`, `:gradient` (default), `:simplex` * `:interpolation` - type of interpolation (for value and gradient): `:none`, `:linear`, `:hermite` (default) or `:quintic` * `:octaves` - number of octaves for combined noise (like FBM), default: 6 * `:lacunarity` - scaling factor for combined noise, default: 2.00 * `:gain` - amplitude scaling factor for combined noise, default: 0.5 * `:normalize?` - should be normalized to `[0,1]` range (true, default) or to `[-1,1]` range (false) For usage convenience 3 ready to use functions are prepared. Return is normalized to `[0,1]` range: * [[noise]] - Perlin Noise (gradient noise, 6 octaves, quintic interpolation) * [[vnoise]] - Value Noise (as in Processing, 6 octaves, hermite interpolation) * [[simplex]] - Simpled Noise (6 octaves) ##### Discrete Noise [[discrete-noise]] is a 1d or 2d hash function for given integers. Returns double from `[0,1]` range. #### Distribution Various real and integer distributions. See [[DistributionProto]] and [[RNGProto]] for functions. To create distribution call [[distribution]] multimethod with name as a keyword and map as parameters.
Random boolean with Mersenne Twister RNG.
Random boolean with Mersenne Twister RNG.
(discrete-noise X)
(discrete-noise X Y)
Discrete noise. Parameters:
Returns double value from [0,1] range
Discrete noise. Parameters: * X (long) * Y (long, optional) Returns double value from [0,1] range
Create distribution object.
First parameter is distribution as a :key
.
Second parameter is a map with configuration.
All distributions accept rng
under :rng
key (default: default-rng
) and some of them accept inverse-cumm-accuracy
(default set to 1e-9
).
Distributions should be called using DistributionProto
and RNGProto
.
The rest parameters goes as follows:
:beta
- :alpha
(default: 2.0) and :beta
(default: 5.0):cauchy
- :mean
(default: 0.0) and :scale
(default: 1.0):chi-squared
- :degrees-of-freedom
(default: 1.0):empirical
- :bean-count
(default: 1000) and :data
as a sequence:enumerated-real
- :data
as a sequence and :probabilities
as a optional sequence:exponential
- :mean
(default: 1.0):f
- :numerator-degrees-of-freedom
(default: 1.0) and :denominator-degrees-of-freedom
(default: 1.0):gamma
- :shape
(default: 2.0) and :scale
(default: 2.0):gumbel
- :mu
(default: 1.0) and :beta
(default: 2.0):laplace
- :mu
(default: 1.0) and :beta
(default: 2.0):levy
- :mu
(default: 0.0) and :c
(default: 1.0):logistic
- :mu
(default: 1.0) and :s
(default: 2.0):log-normal
- :scale
(default: 1.0) and :shape
(default: 1.0):nakagami
- :mu
(default: 1.0) and :omega
(default: 1.0):normal
- :mu
(default: 0.0) and :sd
(default: 1.0):pareto
- :scale
(default: 1.0) and :shape
(default: 1.0):t
- :degrees-of-freedom
(default: 1.0):triangular
- :a
(default: -1.0), :b
(default: 0.0) and :c
(default: 1.0):uniform-real
- :lower
(default: 0.0) and :upper
(default: 1.0):weibull
- :alpha
(default: 2.0) and :beta
(default: 1.0):binomial
- :trials
(default: 20) and :p
(default: 0.5):enumerated-int
- :data
and :probabilities
as a sequences:geometric
- :p
(default: 0.5):hypergeometric
- :population-size
(default: 100), :number-of-successes
(default: 50) and :sample-size
(default: 25):pascal
- :r
(default: 5) and :p
(default: 0.5):poisson
- :p
(default: 0.5), :epsilon
(default: 1.0e-12), :max-iterations
(default: 10000000):uniform-int
- :lower
(default: 0) and :upper
(default: Integer/MAX_VALUE
):zipf
- :number-of-elements
(default: 100) and :exponent
(default: 3.0)Create distribution object. First parameter is distribution as a `:key`. Second parameter is a map with configuration. All distributions accept `rng` under `:rng` key (default: [[default-rng]]) and some of them accept `inverse-cumm-accuracy` (default set to `1e-9`). Distributions should be called using [[DistributionProto]] and [[RNGProto]]. The rest parameters goes as follows: #### Real distributions * `:beta` - `:alpha` (default: 2.0) and `:beta` (default: 5.0) * `:cauchy` - `:mean` (default: 0.0) and `:scale` (default: 1.0) * `:chi-squared` - `:degrees-of-freedom` (default: 1.0) * `:empirical` - `:bean-count` (default: 1000) and `:data` as a sequence * `:enumerated-real` - `:data` as a sequence and `:probabilities` as a optional sequence * `:exponential` - `:mean` (default: 1.0) * `:f` - `:numerator-degrees-of-freedom` (default: 1.0) and `:denominator-degrees-of-freedom` (default: 1.0) * `:gamma` - `:shape` (default: 2.0) and `:scale` (default: 2.0) * `:gumbel` - `:mu` (default: 1.0) and `:beta` (default: 2.0) * `:laplace` - `:mu` (default: 1.0) and `:beta` (default: 2.0) * `:levy` - `:mu` (default: 0.0) and `:c` (default: 1.0) * `:logistic` - `:mu` (default: 1.0) and `:s` (default: 2.0) * `:log-normal` - `:scale` (default: 1.0) and `:shape` (default: 1.0) * `:nakagami` - `:mu` (default: 1.0) and `:omega` (default: 1.0) * `:normal` - `:mu` (default: 0.0) and `:sd` (default: 1.0) * `:pareto` - `:scale` (default: 1.0) and `:shape` (default: 1.0) * `:t` - `:degrees-of-freedom` (default: 1.0) * `:triangular` - `:a` (default: -1.0), `:b` (default: 0.0) and `:c` (default: 1.0) * `:uniform-real` - `:lower` (default: 0.0) and `:upper` (default: 1.0) * `:weibull` - `:alpha` (default: 2.0) and `:beta` (default: 1.0) #### Integer distributions * `:binomial` - `:trials` (default: 20) and `:p` (default: 0.5) * `:enumerated-int` - `:data` and `:probabilities` as a sequences * `:geometric` - `:p` (default: 0.5) * `:hypergeometric` - `:population-size` (default: 100), `:number-of-successes` (default: 50) and `:sample-size` (default: 25) * `:pascal` - `:r` (default: 5) and `:p` (default: 0.5) * `:poisson` - `:p` (default: 0.5), `:epsilon` (default: 1.0e-12), `:max-iterations` (default: 10000000) * `:uniform-int` - `:lower` (default: 0) and `:upper` (default: `Integer/MAX_VALUE`) * `:zipf` - `:number-of-elements` (default: 100) and `:exponent` (default: 3.0)
Get information from distributions.
Get information from distributions.
(lpdf d v)
Log density
Log density
(log-likelihood d vs)
Log likelihood of samples
Log likelihood of samples
(mean d)
Mean
Mean
(icdf d p)
Inversed cumulative probability
Inversed cumulative probability
(lower-bound d)
Lower value
Lower value
(cdf d v)
(cdf d v1 v2)
Cumulative probability.
Cumulative probability.
(likelihood d vs)
Likelihood of samples
Likelihood of samples
(variance d)
Variance
Variance
(pdf d v)
Density
Density
(probability d v)
Probability (PMF)
Probability (PMF)
(upper-bound d)
Higher value
Higher value
(sample d)
Returns random sample.
Returns random sample.
(drand)
(drand mx)
(drand mn mx)
Random double number with Mersenne Twister RNG.
Random double number with Mersenne Twister RNG.
Random float number with Mersenne Twister RNG.
Random float number with Mersenne Twister RNG.
(grand)
(grand stddev)
(grand mean stddev)
Random gaussian double number with Mersenne Twister RNG.
Random gaussian double number with Mersenne Twister RNG.
List of possible noise interpolations as a map of names and values.
List of possible noise interpolations as a map of names and values.
(irand)
(irand mx)
(irand mn mx)
Random integer number with Mersenne Twister RNG.
Random integer number with Mersenne Twister RNG.
(lrand)
(lrand mx)
(lrand mn mx)
Random long number with Mersenne Twister RNG.
Random long number with Mersenne Twister RNG.
(noise x)
(noise x y)
(noise x y z)
Create improved Perlin Noise.
6 octaves, quintic interpolation.
Create improved Perlin Noise. 6 octaves, quintic interpolation.
List of possible noise types as a map of names and values.
List of possible noise types as a map of names and values.
(random-noise-cfg)
Create random noise configuration.
Create random noise configuration.
(random-noise-fn)
(random-noise-fn cfg)
Create random noise function from all possible options.
Optionally provide own configuration cfg
. In this case one of 4 different blending methods will be selected.
Create random noise function from all possible options. Optionally provide own configuration `cfg`. In this case one of 4 different blending methods will be selected.
(randval v1 v2)
(randval prob v1 v2)
Retrun value with given probability (default 0.5)
Retrun value with given probability (default 0.5)
Defines set of random functions for different RNGs or distributions returning primitive values.
Defines set of random functions for different RNGs or distributions returning primitive values.
(->seq t)
(->seq t n)
Returns sequence of random samples limited to optional n
values.
Returns sequence of random samples limited to optional `n` values.
(brandom t)
(brandom t thr)
Boolean random.
Returns true or false with equal probability. You can set probability for true
setting thr
(from [0-1]
range).
See brand
.
Boolean random. Returns true or false with equal probability. You can set probability for `true` setting `thr` (from `[0-1]` range). See [[brand]].
(drandom t)
(drandom t mx)
(drandom t mn mx)
Random double.
For RNGs:
As default returns random double from [0,1)
range.
When mx
is passed, range is set to [0, mx)
. When mn
is passed, range is set to [mn, mx)
.
See drand
.
For distributions, just returns random double (call without parameters).
Random double. For RNGs: As default returns random double from `[0,1)` range. When `mx` is passed, range is set to `[0, mx)`. When `mn` is passed, range is set to `[mn, mx)`. See [[drand]]. For distributions, just returns random double (call without parameters).
(frandom t)
(frandom t mx)
(frandom t mn mx)
Random float.
For RNGs:
As default returns random float from [0,1)
range.
When mx
is passed, range is set to [0, mx)
. When mn
is passed, range is set to [mn, mx)
.
See frand
.
For distributions, just returns random float (call without parameters).
Random float. For RNGs: As default returns random float from `[0,1)` range. When `mx` is passed, range is set to `[0, mx)`. When `mn` is passed, range is set to `[mn, mx)`. See [[frand]]. For distributions, just returns random float (call without parameters).
(grandom t)
(grandom t std)
(grandom t mean std)
Random double from gaussian distribution.
As default returns random double from N(0,1)
.
When std
is passed, N(0,std)
is used. When mean
is passed, distribution is set to N(mean, std)
.
See grand
.
Random double from gaussian distribution. As default returns random double from `N(0,1)`. When `std` is passed, `N(0,std)` is used. When `mean` is passed, distribution is set to `N(mean, std)`. See [[grand]].
(irandom t)
(irandom t mx)
(irandom t mn mx)
Random integer.
For RNGs:
As default returns random integer from full integer range.
When mx
is passed, range is set to [0, mx)
. When mn
is passed, range is set to [mn, mx)
.
See irand
.
For distributions, just returns random integer (call without parameters).
Random integer. For RNGs: As default returns random integer from full integer range. When `mx` is passed, range is set to `[0, mx)`. When `mn` is passed, range is set to `[mn, mx)`. See [[irand]]. For distributions, just returns random integer (call without parameters).
(lrandom t)
(lrandom t mx)
(lrandom t mn mx)
Random long.
For RNGs:
As default returns random long from full long range.
When mx
is passed, range is set to [0, mx)
. When mn
is passed, range is set to [mn, mx)
.
See lrand
.
For distributions, just returns random long (call without parameters).
Random long. For RNGs: As default returns random long from full long range. When `mx` is passed, range is set to `[0, mx)`. When `mn` is passed, range is set to `[mn, mx)`. See [[lrand]]. For distributions, just returns random long (call without parameters).
(set-seed! t v)
Sets seed. Returns RNG or distribution itself.
Sets seed. Returns RNG or distribution itself.
Create Sequence generator. See sequence-generators-list
for names. Parameter size
describes number of dimensions (1-4).
Values are from following values:
:halton
, :sobol
, :default
- range [0-1]
:gaussian
- from N(0,1)
distribution:sphere
- from surface of unit sphere (ie. euclidean distance from origin equals 1.0)Create Sequence generator. See [[sequence-generators-list]] for names. Parameter `size` describes number of dimensions (1-4). Values are from following values: * `:halton`, `:sobol`, `:default` - range `[0-1]` * `:gaussian` - from `N(0,1)` distribution * `:sphere` - from surface of unit sphere (ie. euclidean distance from origin equals 1.0)
List of random sequence generator. See sequence-generator
.
List of random sequence generator. See [[sequence-generator]].
(simplex x)
(simplex x y)
(simplex x y z)
Create Simplex noise. 6 octaves.
Create Simplex noise. 6 octaves.
(vnoise x)
(vnoise x y)
(vnoise x y z)
Value Noise.
6 octaves, Hermite interpolation (cubic, h01).
Value Noise. 6 octaves, Hermite interpolation (cubic, h01).
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close