Pages: 1 [2]   Go Down
Author Topic: Re: Random()  (Read 1302 times)
0 Members and 1 Guest are viewing this topic.
Anaheim CA.
Offline Offline
Faraday Member
**
Karma: 48
Posts: 2935
...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

dhenry doesn't need facts, he has an opinion about everything and he IS NEVER wrong.
Just ask him...

Bob
Logged

--> WA7EMS <--
“The solution of every problem is another problem.” -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you want true randomness, try biasing a diode near the "knee" of the I-V curve (around 0.7V for a silicon diode).  The current will fluctuate randomly
due to thermal noise.

73,
NV1T
Logged

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You already have that diode, in some mcus with a temperature sensor;

But the thermal noise is too small to produce a truly random figure by the onboard adc.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yeah, you might need to amplify it with an op-amp circuit.  I built one of these many moons ago.  Y'all should read this informative article:
http://en.wikipedia.org/wiki/Hardware_random_number_generator

73,
NV1T
Logged

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There is an easier way: reverse connect a npn to form an esaki diode. Power that up via a capacitor + a low. It will form a flasher. The period of its flashes is random and can be easily measured by a timer.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yeah, you can do it with an Esaki (aka tunnel) diode, or an avalanche diode, or a Zener diode, or...

Always more than one way to skin a cat.

However, for iluvplanes' application, sounds like a simple random permutation generator would be sufficient.  I don't think he's really looking for
a cryptographically strong RNG.

73,
NV1T
Logged

Anaheim CA.
Offline Offline
Faraday Member
**
Karma: 48
Posts: 2935
...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No I don't either But *dhenry* Loves to talk. He is one of the most popular people here.

Bob
Logged

--> WA7EMS <--
“The solution of every problem is another problem.” -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

Global Moderator
Melbourne, Australia
Offline Offline
Brattain Member
*****
Karma: 511
Posts: 19367
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Enough insults, thanks.
Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Yeah, you can do it with an Esaki (aka tunnel) diode, or an avalanche diode, or a Zener diode, or...

Zenre is tough. Avalanche slightly easier but it oscillates at too high a frequency to be measured by a mcu.

An oscillator with lots of phase noise (a relaxation oscillator for example) would be ideal for this.

Quote
However, for iluvplanes' application, sounds like a simple random permutation generator would be sufficient.  I don't think he's really looking for
a cryptographically strong RNG.

True.
Logged

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

As expected, here is the output from a rc oscillator (100k+1n) on a hc132: 6000 data points.

Looks pretty random to me.




* random tmr2.PNG (34.38 KB, 695x424 - viewed 12 times.)
Logged

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This one doesn't use a timer. Instead it counts a variable in ram.

5000 data points.

Code:
//generate a random seed
unsigned char rseed2(void) {
  unsigned char mask = 0x80;
  unsigned char tmp = 0;
  unsigned char cnt=0;
  //tmr0_init();    //reset the tmr
 
  do {
    cnt = 0;      //reset the counter
    while (digitalRead(IN_PIN)==0) continue;  //wait for the pin to go high
    //TCCR2B = 0x01;  //start the timer, 1:1 prescaler
    while (digitalRead(IN_PIN)==1) cnt+=1;  //wait for the pin to go low
    //TCCR2B = 0x00;  //stop the timer
    if (cnt & 0x01) tmp |= mask;
    mask = mask >> 1;
  } while (mask);
  return tmp;
}


* random cnt.PNG (35 KB, 709x424 - viewed 11 times.)
Logged

Global Moderator
Melbourne, Australia
Offline Offline
Brattain Member
*****
Karma: 511
Posts: 19367
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Looks pretty random to me.

I think you need to run that through a proper mathematical analysis. "Looking" random isn't really enough. It could just be evenly distributed.
Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Pages: 1 [2]   Go Up
Jump to: