Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

Re: Random Number Generator

Re: Random Number Generator

2011-01-08 by airmaledfw

--- In AVR-Chat@yahoogroups.com, "Chuck Hackett" <egroupscdh@...> wrote:
>
> All I can think of is something like setting up one of the analog inputs as 'free
> floating', turning the gain all the way up, and violating all the "how to avoid ADC
> noise" rules and taking a sample.
> 

This is an idea I had seen posted somewhere long ago and is something I would experiment with if I needed a random number seed. Go with that and post how your results turn out.

Random Number Generator

2011-01-08 by Chuck Hackett

This is mostly a "mind experiment" because I don't have a current need but, is there
a way to obtain a truly random (8-bit is good enough) number on an AVR?  I'm not
talking "random" in the statistically pure sense, just non-deterministic.

I'm only thinking of using it on startup.  

Sampling a "noisy diode" would be great but I want to do it without having to add
external hardware or dedicate an I/O pin to the effort. 

All I can think of is something like setting up one of the analog inputs as 'free
floating', turning the gain all the way up, and violating all the "how to avoid ADC
noise" rules and taking a sample.

I don't think the timers would be helpful because these would tend to be
deterministic and, by nature, run in sync with any code that would be sampling them.


Ideas?

Re: [AVR-Chat] Random Number Generator

2011-01-08 by Jim Wagner

One of the common pseudo-random, non-deterministic schemes is to have  
a free-running timer. You just grab a value when you need a new  
"number". It will be non-deterministic but might not be truly random  
in the statistical sense. It will average to the median.

Jim Wagner
Oregon Research Electronics

On Jan 8, 2011, at 1:39 PM, Chuck Hackett wrote:

> This is mostly a "mind experiment" because I don't have a current  
> need but, is there
> a way to obtain a truly random (8-bit is good enough) number on an  
> AVR? I'm not
> talking "random" in the statistically pure sense, just non- 
> deterministic.
>
> I'm only thinking of using it on startup.
>
> Sampling a "noisy diode" would be great but I want to do it without  
> having to add
> external hardware or dedicate an I/O pin to the effort.
>
> All I can think of is something like setting up one of the analog  
> inputs as 'free
> floating', turning the gain all the way up, and violating all the  
> "how to avoid ADC
> noise" rules and taking a sample.
>
> I don't think the timers would be helpful because these would tend  
> to be
> deterministic and, by nature, run in sync with any code that would  
> be sampling them.
>
> Ideas?
>
>
> 



[Non-text portions of this message have been removed]

RE: [AVR-Chat] Random Number Generator

2011-01-08 by Chuck Hackett

> From: Jim Wagner
> 
> One of the common pseudo-random, non-deterministic schemes is to have
> a free-running timer. You just grab a value when you need a new
> "number". It will be non-deterministic but might not be truly random
> in the statistical sense. It will average to the median.

I don't think this is non-deterministic unless the time at which the sample the
timer is taken is subject to outside events (like receiving terminal input, etc.) or
the timer clock is derived from a separate (from the CPU) clock that is very
unstable.  

Using the processor clock, if you start the timer and then process cpu-only activity
for two weeks and then sample the timer it will always have the same value because
the timer and the code are running in lock step.

Remember, I said that I was looking for the random number at startup, implying that
it is before there are any external events available ...

One thing that might work is an R/C driven free-running timer.  If you wait a
relatively long time (long in terms of the relative clock speed relationship between
the R/C and CPU clock) and pick of the lower 8 bits it might be enough.
 
Cheers,

Chuck Hackett
"Good judgment comes from experience, experience comes from bad judgment"
7.5" gauge Union Pacific Northern (4-8-4) 844 http://www.whitetrout.net/Chuck

Re: [AVR-Chat] Re: Random Number Generator

2011-01-08 by enkitec@gmail.com

Use the Watchdog to capture the Timer.
     Change the Watchdog prescaler after each capture.

     Mark
Show quoted textHide quoted text
On 08-Jan-11 20:12, airmaledfw wrote:
> --- In AVR-Chat@yahoogroups.com, "Chuck Hackett"<egroupscdh@...>  wrote:
>> All I can think of is something like setting up one of the analog inputs as 'free
>> floating', turning the gain all the way up, and violating all the "how to avoid ADC
>> noise" rules and taking a sample.
>>
> This is an idea I had seen posted somewhere long ago and is something I would experiment with if I needed a random number seed. Go with that and post how your results turn out.
>
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>
>

Re: [AVR-Chat] Random Number Generator

2011-01-08 by Clark Martin

\
On Jan 8, 2011, at 1:39 PM, Chuck Hackett wrote:

> This is mostly a "mind experiment" because I don't have a current need but, is there
> a way to obtain a truly random (8-bit is good enough) number on an AVR? I'm not
> talking "random" in the statistically pure sense, just non-deterministic.
> 
> I'm only thinking of using it on startup. 
> 
> Sampling a "noisy diode" would be great but I want to do it without having to add
> external hardware or dedicate an I/O pin to the effort. 
> 
> All I can think of is something like setting up one of the analog inputs as 'free
> floating', turning the gain all the way up, and violating all the "how to avoid ADC
> noise" rules and taking a sample.
> 
> I don't think the timers would be helpful because these would tend to be
> deterministic and, by nature, run in sync with any code that would be sampling them.
> 
> 

I recently started a project to make electronic dice.  I'm using the libc (pseudo) random number routine.  I figured it would be could enough for my purposes provided I could come up with a random seed.  I set up a timer to free run and I read it on the first press of the roll button and pass it as a seed to random number routine.  A really fast counter with a human reaction time should provide a reasonably random seed.  I can't use just the timer and button push for all my random numbers as I need several per roll (two die and multiple random die face appearances as they "roll").  

A long time ago I setup a random number generator using three inverters in a loop.  This makes for a very fast oscillator, as fast as the logic family can go pretty much.  I fed this to an 8 bit counter connected to the CPU.  It was not synchronized with the processor clock and was quite a bit faster.  



__
> 
> 

Clark Martin
Redwood City, CA, USA
Macintosh / Internet Consulting

"I'm a designated driver on the Information Super Highway"



[Non-text portions of this message have been removed]

Re: Random Number Generator

2011-01-10 by Eugene

In my humble opinion the best way is using the noise of p-n transition, well let it be 2 OPs more in one soic8 (for example) and some additional smd components - it's much better than floating inputs.
If you are going to use them you should eliminate possible regular external influences (just in mind: for example you have a rotating radar not far from your equipment and you'll have a regular EM influence on your floating inputs). That may break down randomness of spontaneous signal :)

A few time ago my PCB manufacturer made unconditional PCBs with bad vias. There is an analog part to operate in uVs and we had spontaneous noises in signal - just move a hand over the working board. That's about floating or semi-floating inputs.

Best regards,
Eugene.

--- In AVR-Chat@yahoogroups.com, "Chuck Hackett" <egroupscdh@...> wrote:
Show quoted textHide quoted text
>
> This is mostly a "mind experiment" because I don't have a current need but, is there
> a way to obtain a truly random (8-bit is good enough) number on an AVR?  I'm not
> talking "random" in the statistically pure sense, just non-deterministic.
> 
> I'm only thinking of using it on startup.  
> 
> Sampling a "noisy diode" would be great but I want to do it without having to add
> external hardware or dedicate an I/O pin to the effort. 
> 
> All I can think of is something like setting up one of the analog inputs as 'free
> floating', turning the gain all the way up, and violating all the "how to avoid ADC
> noise" rules and taking a sample.
> 
> I don't think the timers would be helpful because these would tend to be
> deterministic and, by nature, run in sync with any code that would be sampling them.
> 
> 
> Ideas?
>

Re: [AVR-Chat] Re: Random Number Generator

2011-01-10 by David VanHorn

When I hear the word "Random", I get nervous.

One version of "Random" actually means "Unpredictable".  Thermal
noise, radioactive decay.. Useful for cryptographic one time pads.
The other actually means "Gaussian".  PN sequence, etc.

For a dice app, I'd use a long PN generator clocked on each iteration
through the main loop (or idle) and then grab the output whenever the
dice are "rolled", such that the register is clocked far more
frequently than it is used.

Re: [AVR-Chat] Re: Random Number Generator

2011-01-10 by Ken Holt

Or, if a battery is used for VCC: every time you'd like a new 8 bit
seed for the code PN, read your battery voltage 8 times with the
10 bit ADC, use the LSB of each read to construct the seed.
No extra external parts!


David VanHorn wrote:
Show quoted textHide quoted text
>
> When I hear the word "Random", I get nervous.
>
> One version of "Random" actually means "Unpredictable". Thermal
> noise, radioactive decay.. Useful for cryptographic one time pads.
> The other actually means "Gaussian". PN sequence, etc.
>
> For a dice app, I'd use a long PN generator clocked on each iteration
> through the main loop (or idle) and then grab the output whenever the
> dice are "rolled", such that the register is clocked far more
> frequently than it is used.
>
>

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.