Closed joshua-glazer closed 3 years ago
Based on this reddit thread it appears that it takes a few days for the pseudorandom sequence to roll over, and since in your paper you only use around 250 measurements, I think it's more than reasonable to use a single random seed in a test. For a new test it's fairly easy to reset the Arduino to obtain a new random seed, and for example, running the python script to take a new measurement resets the Arduino, so it's almost automatic to get a new seed.
This Arduino thread provides a quick and simple method of generating a random seed based on 32 measurements of the floating analog pin. I've tested it out and on my end it appears to give a much wider range of seed values that can be used in randomSeed()
.
From my testing, the values for
i_ledON
andi_ledOFF
tend to be very similar even after callingrandomSeed()
each time inloop()
. I've identified a few potential causes:analogRead()
on a floating pin (e.g. pin 0) and using this as the seed forrandomSeed()
. However on testing this, it appears that I tend to always measure analog values in a very narrow range, centered around 190 in my setup. Often I measure the same value multiple times.randomSeed()
only once, at the beginning of the code. But in this project, it is called every time inloop()
. When callingrandomSeed()
, a pseudorandom sequence is generated, and from my understanding, if you pass the same value torandomSeed()
and callrandom()
with the same min and max values, you will be using the same sequence and obtain the same first value in the sequence each time.Given the small range of values, if the same
analogRead()
value was measured (given the small range of values), on 2 different runs throughloop()
, the output ofrandom()
will be the same first value of the pseudorandom sequence. And perhaps there are similar values even when the random seed is different, because the analog value measured byanalogRead()
is similar each time, but on this point I am less certain.