random-wemos-d1

chris-cross/random-wemos-d1/random-wemos-d1

No description
random-wemos-d1
@/random-wemos-d1
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-wemos-d1
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 chris-cross/random-wemos-d1 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 = unsigned int;

{{ GENERATED_CODE }}

void evaluate(Context ctx) {
    unsigned int* seedp = getState(ctx);
    if (isInputDirty<input_RST>(ctx))
        *seedp = (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));
    }
}