Go Down

Topic: Re: Random() (Read 2651 times)previous topic - next topic

Docedison

#15
Nov 18, 2012, 11:43 pm
dhenry doesn't need facts, he has an opinion about everything and he IS NEVER wrong.

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

#16
Nov 19, 2012, 11:19 pm
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

#17
Nov 19, 2012, 11:22 pm
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

#18
Nov 20, 2012, 03:14 am
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

#19
Nov 20, 2012, 03:28 am
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

#20
Nov 20, 2012, 03:36 am
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

#21
Nov 20, 2012, 07:59 am
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

#22
Nov 20, 2012, 08:19 am
Enough insults, thanks.
Please post technical questions on the forum, not by personal message. Thanks!

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

dhenry

#23
Nov 20, 2012, 12:55 pm
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

#24
Nov 21, 2012, 12:21 am
As expected, here is the output from a rc oscillator (100k+1n) on a hc132: 6000 data points.

Looks pretty random to me.

dhenry

#25
Nov 21, 2012, 12:29 am
This one doesn't use a timer. Instead it counts a variable in ram.

5000 data points.

Code: [Select]
`//generate a random seedunsigned 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

#26
Nov 21, 2012, 12:33 am
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.
Please post technical questions on the forum, not by personal message. Thanks!

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

Go Up

Please enter a valid email to subscribe