random

wayland/random/random

Generates pseudo-random numbers in range [0; 1). Uses a linear congruential generator algorithm.
random
@/random
Generates pseudo-random numbers in range [0; 1). Uses a linear congruential generator algorithm.
SEEDnumber
A new seed value for the generator in range [0; 1]. Used only on `RST` pulse.
RSTpulse
Initializes the generator with a new `SEED` value. You should initialize with a truly random value at least once (usually on boot), otherwise you’ll get the same number sequence on each program run.
UPDpulse
Triggers output update, that is generates the next pseudo-random number.
random
OUT
SEED
RST
UPD
OUTnumber
The last pseudo-random value in range [0; 1)
To use the node in your project you should have the wayland/random library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.

C++ implementation

{{#global}}
#include <limits.h>
{{/global}}

using State = long unsigned int;

{{ GENERATED_CODE }}

void evaluate(Context ctx) {
    long unsigned int* seedp = getState(ctx);
    if (isInputDirty<input_RST>(ctx))
        *seedp = (long unsigned int)(getValue<input_SEED>(ctx) * ULONG_MAX);

    if (isInputDirty<input_UPD>(ctx)) {
        int rnd = rand_r(seedp);
        emitValue<output_OUT>(ctx, (Number)rnd / ((Number)RAND_MAX + 1.0));
    }
}