Pages: [1]   Go Down
Author Topic: Eccentric obsessive fellow needs your help with seeding random  (Read 1678 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 178
Posts: 12289
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


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.
Logged

Boston Suburbs
Offline Offline
God Member
*****
Karma: 14
Posts: 955
I am above your silly so-called "Laws", Mister Ohm.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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;

Randomseed(analogRead(0));
j=random(100);
for (int i=1; i<j; i++) {
Seed=analogRead(0) * analogRead(1) + analogRead(2);
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.
« Last Edit: May 18, 2011, 01:02:10 am by focalist » Logged

When the testing is complete there will be... cake.

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 178
Posts: 12289
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


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

Are you interested in helping?
« Last Edit: May 18, 2011, 02:33:48 am by Coding Badly » Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 170
Posts: 12487
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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;
}


Logged

Rob Tillaart

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

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 178
Posts: 12289
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 170
Posts: 12487
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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

Rob Tillaart

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

Seattle, WA
Offline Offline
God Member
*****
Karma: 8
Posts: 673
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged


Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 178
Posts: 12289
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

So I PM'd to sign up

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?
Logged

Seattle, WA
Offline Offline
God Member
*****
Karma: 8
Posts: 673
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

"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!
Logged


Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 178
Posts: 12289
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I see now that it uses the watchdog.  Fascinating approach!

Thanks!
Logged

Pages: [1]   Go Up
Jump to: