Go Down

Topic: Re: Random() (Read 1 time) previous topic - next topic

Docedison

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

Bob
--> 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

NV1T

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

dhenry

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.

NV1T

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

dhenry

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.

NV1T

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

Docedison

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

Bob
--> 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

Nick Gammon

Enough insults, thanks.
http://www.gammon.com.au/electronics

dhenry

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.

dhenry

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

Looks pretty random to me.



dhenry

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

5000 data points.

Code: [Select]
//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;
}


Nick Gammon

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.
http://www.gammon.com.au/electronics

Go Up