Random number generation algorithm

I’m trying to find random number generation algorithm, I also added the random number library to it but it doesn’t work.
I’m trying to run nkrkv/random node but it has a lot of errors and it doesn’t work.
Does anybody know how could I fix it?
Thank you so much.

Hi Claudia,

I’ve fixed the library for the arduino at least (I haven’t tested it on other platforms):

Thank you so much.
Unfortunately it did not work, the error shown is the following one:

/ws/sketchbook/57c9cb320eba029614c487630dd3ce583bae08dcaa911201509ab61852ec74bc/sketch/sketch.ino:1256:23: error: no matching function for call to ‘rand_r’
int rnd = rand_r(seedp);
/ws/arduino_data/packages/xod/tools/emscripten/1.39.2/emscripten/system/include/libc/stdlib.h:106:5: note: candidate function not viable: no known conversion from ‘unsigned long *’ to ‘unsigned int *’ for 1st argument
int rand_r (unsigned *);
/ws/sketchbook/57c9cb320eba029614c487630dd3ce583bae08dcaa911201509ab61852ec74bc/sketch/sketch.ino:1253:70: warning: implicit conversion from ‘unsigned long’ to ‘float’ changes value from 4294967295 to 4294967296 [-Wimplicit-int-float-conversion]
seedp = (long unsigned int)(getValue<input_SEED>(ctx) * ULONG_MAX);
~ ^~~~~
/ws/arduino_data/packages/xod/tools/emscripten/1.39.2/emscripten/system/include/libc/limits.h:33:32: note: expanded from macro ‘ULONG_MAX’
#define ULONG_MAX (2UL
1 warning and 1 error generated.
shared:ERROR: ‘/ws/arduino_data/packages/xod/tools/emscripten/1.39.2/bin/clang++ -target wasm32-unknown-emscripten -D_EMSCRIPTEN_major=1 -DEMSCRIPTEN_minor=39 -DEMSCRIPTEN_tiny=1 -D_LIBCPP_ABI_VERSION=2 -Dunix -Dunix -Dunix_ -Werror=implicit-function-declaration -Xclang -nostdsysteminc -Xclang -isystem/ws/arduino_data/packages/xod/tools/emscripten/1.39.2/emscripten/system/include/libcxx -Xclang -isystem/ws/arduino_data/packages/xod/tools/emscripten/1.39.2/emscripten/system/lib/libcxxabi/include -Xclang -isystem/ws/arduino_data/packages/xod/tools/emscripten/1.39.2/emscripten/system/include/compat -Xclang -isystem/ws/arduino_data/packages/xod/tools/emscripten/1.39.2/emscripten/system/include -Xclang -isystem/ws/arduino_data/packages/xod/tools/emscripten/1.39.2/emscripten/system/include/libc -Xclang -isystem/ws/arduino_data/packages/xod/tools/emscripten/1.39.2/emscripten/system/lib/libc/musl/arch/emscripten -Xclang -isystem/ws/arduino_data/packages/xod/tools/emscripten/1.39.2/emscripten/system/local/include -DLLVM_ROOT=/ws/arduino_data/packages/xod/tools/emscripten/1.39.2/bin -DARDUINO_WASM_SIMULATION -DARDUINO_ARCH_WASM -O2 -std=c++11 -nostdlib -fno-exceptions -fno-rtti -c -I/tmp/arduino-sketch-E7DC933EF43094E46884547BDBC3FDB8/sketch -I/ws/arduino_data/packages/xod/hardware/wasm/0.3.2/cores/simulation -I/ws/arduino_data/packages/xod/hardware/wasm/0.3.2/variants/simulation -DEMSCRIPTEN /tmp/arduino-sketch-E7DC933EF43094E46884547BDBC3FDB8/sketch/sketch.ino.cpp -Xclang -isystem/ws/arduino_data/packages/xod/tools/emscripten/1.39.2/emscripten/system/include/SDL -c -o /tmp/arduino-sketch-E7DC933EF43094E46884547BDBC3FDB8/preproc/ctags_target_for_gcc_minus_e.cpp -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr’ failed (1)
Error during build: exit status 1

The generated C++ code contains errors. It can be due to a bad node implementation
or if your board is not compatible with XOD runtime code. The original compiler error
message is above. Fix C++ errors to continue. If you believe it is a bug, report the
problem to XOD developers.

I cannot make it work :frowning:

Are you trying to run the example in the simulator? If so, it will not work. Try uploading it to a board and running in debug mode (tick the Debug after upload checkbox):

Then you should be able to use the tweak-pulse node to generate pseudo random numbers:

unfortunately this random number node doesn’t work even when I try to use his method, this is the screenshot.
can you see any mistake?
thank you!!

For starters, you are using a digital pin for the analog-input, so it will always be 0 or 1. This is providing the seed for your random number, so you will always get one of two numbers out.

After switching to an analog pin, you will still need to connect something to that pin to provide a non-zero number for the seed that is constantly changing, or your random output will not change. See comments in the code wayland posted.

I’ve alredy tried that, and I’m not runnig it is simulator just in debug mode but the problem is with c++ code as the error mentions, it does not even upload the code on the board.
And I’m using analog port and that D17 on screenshot is because of gpio conversation because I’m not using Ardoino, I’m using esp8266.

Sorry. I zoomed in on program & didn’t even notice the compile errors. I don’t know how to help with those & don’t have that hardware to test on.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.

Hi @claudiavallejo398 ,

If you’re still looking for a random number generator for the esp8266, I’ve just published the following library: