rng

Provides a deterministic pseudo-random number generator. The RNG type represents the internal state of the generator. It needs to be initialized using a seed and advanced each time a pseudo-random value is extracted.

Initialize the generator

RNG rngInitialize();
RNG rngInitialize(int seed);
RNG rngInitialize(float seed);

Perturb the generator by an additional seed. This can be used to pass an altered version of the generator to functions, so that different values are generated within.

RNG rngPerturb(RNG rng, int seed);
RNG rngPerturb(RNG rng, float seed);

Advance the generator state. The RNG must be replaced by this function's result every time a new number is to be generated.

RNG rngAdvance(RNG rng);

Get the current pseudo-random integer value. If limit is present, a value uniformly distributed between 0 and limit (excluding limit) is returned. Otherwise, any 32-bit integer value can be returned.

int rngGetInt(RNG rng);
int rngGetInt(RNG rng, int limit);

Get the current pseudo-random floating-point value. A value uniformly distributed between 0 and limit is returned. The limit is 1 if not specified.

float rngGetFloat(RNG rng);
float rngGetFloat(RNG rng, float limit);

Finally, a set of functions is available that generates a value and advances the RNG's state at the same time. They are available for most base GLSL types. The optional second argument is the limit as specified above (always scalar). These are: rngInt, rngFloat, rngIvec2, rngIvec3, rngIvec4, rngVec2, rngVec3, rngVec4.

Example

generator MyVertex structureTop(RNG rng, vec3 origin) {
    vec3 a = origin;
    vec3 b = a+rngVec3(rng);
    vec3 c = a+rngVec3(rng);
    triangle(a, b, c);
}

generator MyVertex recursiveStructure(RNG rng, vec3 origin) {
    structureBottom(rngPerturb(rng, 1), origin),
    structureMiddle(rngPerturb(rng, 2), origin),
    structureTop(rngPerturb(rng, 3), origin);
}