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 (:jdk
) 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.
To create generator call sequence-generator
with generator name and vector size.
Following generators are available:
:halton
- Halton low-discrepancy sequence; range [0,1]:sobol
- Sobol low-discrepancy sequence; range [0,1]:r2
- R2 low-discrepancy sequence; range [0,1], more...:sphere
- uniformly random distributed on unit sphere:gaussian
- gaussian distributed (mean=0, stddev=1):default
- uniformly random; range:[0,1]:halton
, :sobol
and :r2
can be also randomly jittered according to this article. Call jittered-sequence-generator
.
After creation you get lazy sequence
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 combined in following variants:
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. Returning value from [0,1]
range:
noise
- Perlin Noise (gradient noise, 6 octaves, quintic interpolation)vnoise
- Value Noise (as in Processing, 6 octaves, hermite interpolation)simplex
- Simplex Noise (6 octaves)For random noise generation you can use random-noise-cfg
and random-noise-fn
. Both can be feed with configuration. Additional configuration:
:generator
can be set to one of the noise variants, defaults to :fbm
:warp-scale
- 0.0 - do not warp, >0.0 warp:warp-depth
- depth for warp (default 1.0, if warp-scale is positive)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 (`:jdk`) 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. To create generator call [[sequence-generator]] with generator name and vector size. Following generators are available: * `:halton` - Halton low-discrepancy sequence; range [0,1] * `:sobol` - Sobol low-discrepancy sequence; range [0,1] * `:r2` - R2 low-discrepancy sequence; range [0,1], [more...](http://extremelearning.com.au/unreasonable-effectiveness-of-quasirandom-sequences/) * `:sphere` - uniformly random distributed on unit sphere * `:gaussian` - gaussian distributed (mean=0, stddev=1) * `:default` - uniformly random; range:[0,1] `:halton`, `:sobol` and `:r2` can be also randomly jittered according to this [article](http://extremelearning.com.au/a-simple-method-to-construct-isotropic-quasirandom-blue-noise-point-sequences/). Call [[jittered-sequence-generator]]. After creation you get lazy sequence ### 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 combined in following variants: * 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. Returning value from `[0,1]` range: * [[noise]] - Perlin Noise (gradient noise, 6 octaves, quintic interpolation) * [[vnoise]] - Value Noise (as in Processing, 6 octaves, hermite interpolation) * [[simplex]] - Simplex Noise (6 octaves) For random noise generation you can use [[random-noise-cfg]] and [[random-noise-fn]]. Both can be feed with configuration. Additional configuration: * `:generator` can be set to one of the noise variants, defaults to `:fbm` * `:warp-scale` - 0.0 - do not warp, >0.0 warp * `:warp-depth` - depth for warp (default 1.0, if warp-scale is positive) #### 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.
(->seq rng)
(->seq rng n)
Returns lazy sequence of random samples (can be limited to optional n
values).
Returns lazy sequence of random samples (can be limited to optional `n` values).
(billow-noise)
(billow-noise cfg__5042__auto__)
Create billow noise function with optional configuration.
Create billow noise function with optional configuration.
Random boolean with default RNG.
Returns true or false with equal probability. You can set p
probability for true
Random boolean with default RNG. Returns true or false with equal probability. You can set `p` probability for `true`
(brandom rng)
(brandom rng p)
Random boolean with provided RNG
Random boolean with provided RNG
(continuous? d)
Does distribution support continuous domain?
Does distribution support continuous domain?
(covariance d)
Distribution covariance matrix (for multivariate distributions)
Distribution covariance matrix (for multivariate distributions)
Default normal distribution (u=0.0, sigma=1.0).
Default normal distribution (u=0.0, sigma=1.0).
(dimensions d)
Distribution dimensionality
Distribution dimensionality
(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.
:key
.All distributions accept rng
under :rng
key (default: default-rng
) and some of them accept inverse-cumm-accuracy
(default set to 1e-9
).
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`).
(distribution-id d)
Distribution identifier as keyword.
Distribution identifier as keyword.
(distribution-parameters d)
(distribution-parameters d all?)
Distribution highest supported value.
When all?
is true, technical parameters are included, ie: :rng
and :inverser-cumm-accuracy
.
Distribution highest supported value. When `all?` is true, technical parameters are included, ie: `:rng` and `:inverser-cumm-accuracy`.
(drand)
(drand mx)
(drand mn mx)
Random double number with default RNG.
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)
.
Random double number with default RNG. 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)`.
(drandom rng)
(drandom rng mx)
(drandom rng mn mx)
Random double number with provided RNG
Random double number with provided RNG
(fbm-noise)
(fbm-noise cfg__5042__auto__)
Create fbm noise function with optional configuration.
Create fbm noise function with optional configuration.
(flip)
(flip p)
Returns 1 with given probability, 0 otherwise
Returns 1 with given probability, 0 otherwise
(flipb)
(flipb p)
Returns true with given probability, false otherwise
Returns true with given probability, false otherwise
(frand)
(frand mx)
(frand mn mx)
Random double number with default RNG.
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)
.
Random double number with default RNG. 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)`.
(frandom rng)
(frandom rng mx)
(frandom rng mn mx)
Random double number with provided RNG
Random double number with provided RNG
(grand)
(grand stddev)
(grand mean stddev)
Random gaussian double number with default RNG.
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)
.
Random gaussian double number with default RNG. 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)`.
(grandom rng)
(grandom rng stddev)
(grandom rng mean stddev)
Random gaussian double number with provided RNG
Random gaussian double number with provided RNG
(irand)
(irand mx)
(irand mn mx)
Random integer number with default RNG.
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)
.
Random integer number with default RNG. 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)`.
(irandom rng)
(irandom rng mx)
(irandom rng mn mx)
Random integer number with provided RNG
Random integer number with provided RNG
(jittered-sequence-generator seq-generator dimensions)
(jittered-sequence-generator seq-generator dimensions jitter)
Create jittered sequence generator.
Suitable for :r2
, :sobol
and :halton
sequences.
jitter
parameter range is from 0
(no jitter) to 1
(full jitter). Default: 0.25.
See also sequence-generator
.
Create jittered sequence generator. Suitable for `:r2`, `:sobol` and `:halton` sequences. `jitter` parameter range is from `0` (no jitter) to `1` (full jitter). Default: 0.25. See also [[sequence-generator]].
(log-likelihood d vs)
Log likelihood of samples
Log likelihood of samples
(lower-bound d)
Distribution lowest supported value
Distribution lowest supported value
(lrand)
(lrand mx)
(lrand mn mx)
Random long number with default RNG.
As default returns random long from full integer range.
When mx
is passed, range is set to [0, mx)
. When mn
is passed, range is set to [mn, mx)
.
Random long number with default RNG. As default returns random long from full integer range. When `mx` is passed, range is set to `[0, mx)`. When `mn` is passed, range is set to `[mn, mx)`.
(lrandom rng)
(lrandom rng mx)
(lrandom rng mn mx)
Random long number with provided RNG
Random long number with provided RNG
(means d)
Distribution means (for multivariate distributions)
Distribution means (for multivariate distributions)
(noise x)
(noise x y)
(noise x y z)
Improved Perlin Noise.
6 octaves, quintic interpolation.
Improved Perlin Noise. 6 octaves, quintic interpolation.
List of possible noise generators as a map of names and functions.
List of possible noise generators as a map of names and functions.
List of possible noise interpolations as a map of names and values.
List of possible noise interpolations as a map of names and values.
List of possible noise types as a map of names and values.
List of possible noise types as a map of names and values.
(observe d vs)
Log likelihood of samples. Alias for log-likelihood
.
Log likelihood of samples. Alias for [[log-likelihood]].
(observe1 d v)
Log of probability/density of the value. Alias for lpdf
.
Log of probability/density of the value. Alias for [[lpdf]].
(random-noise-cfg)
(random-noise-cfg pre-config)
Create random noise configuration.
Optional map with fixed values.
Create random noise configuration. Optional map with fixed values.
(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)
(randval prob)
(randval v1 v2)
(randval prob v1 v2)
Retrun value with given probability (default 0.5)
Retrun value with given probability (default 0.5)
(ridgedmulti-noise)
(ridgedmulti-noise cfg__5042__auto__)
Create ridgedmulti noise function with optional configuration.
Create ridgedmulti noise function with optional configuration.
Create RNG for given name (as keyword) and optional seed. Return object enhanced with [[RNGProto]]. See: rngs-list
for names.
Create RNG for given name (as keyword) and optional seed. Return object enhanced with [[RNGProto]]. See: [[rngs-list]] for names.
Create Sequence generator. See sequence-generators-list
for names.
Values:
:r2
, :halton
, :sobol
, :default
- range [0-1] for each dimension
:gaussian
- from N(0,1)
distribution:sphere
- from surface of unit sphere (ie. euclidean distance from origin equals 1.0)Possible dimensions:
:r2
- 1-15:halton
- 1-40:sobol
- 1-1000See also jittered-sequence-generator
.
Create Sequence generator. See [[sequence-generators-list]] for names. Values: * `:r2`, `:halton`, `:sobol`, `:default` - range `[0-1] for each dimension` * `:gaussian` - from `N(0,1)` distribution * `:sphere` - from surface of unit sphere (ie. euclidean distance from origin equals 1.0) Possible dimensions: * `:r2` - 1-15 * `:halton` - 1-40 * `:sobol` - 1-1000 * the rest - 1+ See also [[jittered-sequence-generator]].
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)
Simplex noise. 6 octaves.
Simplex noise. 6 octaves.
(single-noise)
(single-noise cfg__5042__auto__)
Create single noise function with optional configuration.
Create single noise function with optional configuration.
(source-object d)
Returns Java or proxy object from backend library (if available)
Returns Java or proxy object from backend library (if available)
(synced-rng m)
(synced-rng m seed)
Create synchronized RNG for given name and optional seed. Wraps rng
method.
Create synchronized RNG for given name and optional seed. Wraps [[rng]] method.
(upper-bound d)
Distribution highest supported value
Distribution highest supported value
(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).
(warp-noise-fn)
(warp-noise-fn noise)
(warp-noise-fn noise scale)
(warp-noise-fn noise scale depth)
Create warp noise (see Inigo Quilez article).
Parameters:
Normalization of warp noise depends on normalization of noise function.
Create warp noise (see [Inigo Quilez article](http://www.iquilezles.org/www/articles/warp/warp.htm)). Parameters: * noise function, default: vnoise * scale factor, default: 4.0 * depth (1 or 2), default 1 Normalization of warp noise depends on normalization of noise function.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close