Go Down

### Topic: Eccentric obsessive fellow needs your help with seeding random (Read 5964 times)previous topic - next topic

##### May 18, 2011, 06:18 am

Seeding the random number generator is occasionally discussed on the forum.  I think I have something that works well.  The technique generates about 150 KB of data per day.  Which is probably fast enough for seeding the Arduino random number generator (~2.5 seconds).

But it will take approximately 77 days (ouch!) to generate enough data to perform proper statistical tests.  The help I need is rather simple.  I need lots of people to run a Sketch, collect the binary data, and send me the file(s).  If you would like to help, please reply or send a Personal Message.

#### focalist

#1
##### May 18, 2011, 07:41 amLast Edit: May 18, 2011, 08:02 am by focalist Reason: 1
Seeding a random number generator selects where in it's sequence you would like to start- but the sequence itself is actually a formula which returns the sequence the same each time.  Since it's a long, that gives us +- 2.1 billion positions, or a 4.2 billion number sequence (non repeating).  That alone is a big number base, effectively more random than can be predicted.

I've always seeded random with a floating analog input..  that gives 1024 potential start points out of the roughly 4.2 billion number sequence- though I suppose the actual seeds float around 512 in a bell curve type thing, I don't think analogread on a port returns a flat profile for returned numbers- so the noise may be clustered around the center.  If we throw a couple more reads at it, and shake it up, we'll get a wider number of potential start points, making it that much more random.

The seed is Long, -2,147,483,648 to 2,147,483,648 - which selects a start point in the sequence.  How about:

long Seed;

j=random(100);
for (int i=1; i<j; i++) {
Randomseed(Seed);
}

Three analog reads, giving a total of 1024*1024*1024 (over a billion, a quarter of the entire sequence) potential start points in the random sequence... done a random number of times (1-100 that is).  That's MUCH more random than can be predicted, effectively making it as close to totally random as one can get without getting funky with their own algorithms.. and even then, you are just making your sequence and substituting yours for the system's.

Random is random if the sequence cannot be predicted from the outside.
When the testing is complete there will be... cake.

#2
##### May 18, 2011, 08:50 amLast Edit: May 18, 2011, 09:33 am by Coding Badly Reason: 1

My testing reveals that analogRead on an unconnected pin is a poor choice for generating a seed.

Are you interested in helping?

#### robtillaart

#3
##### May 18, 2011, 09:50 am
I want to help, send me your sketch and instructions.

BTW you are familiar with - http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1294239019 - discussion which includes fetching a realRandom from the net.

@Don

What about using 32x the last bit as it fluctuates the most, something like
Code: [Select]
`unsigned long getSeed(){  unsigned long rv = 0;  for (int i=0; i<32; i++)   {     if (analogRead(0) % 2) bitSet(rv,i);     delay(rv%5);  // give the ADC some time to fluctuate  }return rv;}`

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

#4
##### May 18, 2011, 10:22 am
I want to help, send me your sketch and instructions.

Excellent!  I'm on my way to bed so I'll send (PM) you the Sketch and instructions when I get up.

Quote
BTW you are familiar with - http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1294239019 - discussion which includes fetching a realRandom from the net.

I like the idea and I hope to do some more testing on it.

But I can imagine a potential problem.  Typically, a seed is generated when power is first applied (in setup).  At that point, the processor is presumably still warming.  This could create a pattern in the readings.

And I know of a problem.  The ATtiny85 processor always returns even values when reading the internal temperature sensor.  Well, I can't say they all do but mine do.  According to the datasheet, that is actually within the specifications.

#### robtillaart

#5
##### May 18, 2011, 10:35 am

More specifically I meant reply 13, fetching a seed from  random.org   a webservice to provide random bits...
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

#### maniacbug

#6
##### May 19, 2011, 02:56 am
So I PM'd to sign up.  Just curious...  does it rely on the hardware, or could you port it to a higher powered platform and get the same results?

#7
##### May 19, 2011, 03:04 am

And I PM'd back.  Thanks!

Quote
Just curious...  does it rely on the hardware

Yes.

Quote
or could you port it to a higher powered platform and get the same results?

"Higher powered platform"?  Like a PC?  Or do you mean something like an Arduino Mega?

#### maniacbug

#8
##### May 19, 2011, 04:08 am

"Higher powered platform"?  Like a PC?  Or do you mean something like an Arduino Mega?\

Yeah I got it now.  I did mean a PC (or a Mac!)  Nevermind...  I see now that it uses the watchdog.  Fascinating approach!

#9
##### May 19, 2011, 04:14 am
Quote
I see now that it uses the watchdog.  Fascinating approach!

Thanks!

Go Up

Please enter a valid email to subscribe

To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy