I’m writing a little PRNG class that uses the Multiply-with-carry algorithm written by George Marsaglia.
The class makes a reading of the first 4 analog pin, then it combines those readings into 2 32-bit variables used by the PRNG to generate random numbers.
But I’m having a problem with my class because it seems that if I initialize the algorithm into the class constructor, when I go to ask random numbers to my class I only get a series of 0s: the class seems not initialized. If I explicitely call the initialize() function into the setup() routine, the class does work. I would to avoid an explicit call to initialize() method beacuse I would like to do that before the user can manipulate the pins.
Yu can try this by downloading the attached library, install it into your /libraries folder, then call the example that you find in Examples/simplePRNG.
Fash the sketch as it, and then decomment the row “//initialize();” into the setup() routine and flash it again.
Can anyone explain why it doesn’t work?
simplePRNG.zip (2.55 KB)