cbachhuber / G2GDelay

Glass-to-Glass delay measurement system
Other
9 stars 5 forks source link

The randomness is not very random #3

Closed joshua-glazer closed 3 years ago

joshua-glazer commented 3 years ago

From my testing, the values for i_ledON and i_ledOFF tend to be very similar even after calling randomSeed() each time in loop(). I've identified a few potential causes:

Given the small range of values, if the same analogRead() value was measured (given the small range of values), on 2 different runs through loop(), the output of random() 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 by analogRead() is similar each time, but on this point I am less certain.

joshua-glazer commented 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().