generating random numbers via eeprom write?

Go To Last Post
21 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi folks!

I have to produce 4 seldom used random numbers, which will be stored in the internal eeprom!
I know there is a way with the ADC and a Z - diode
but I don't like to spend external components and/or additional pins!

So I thought about the eeprom writing time! How constant is the length of this process?
Would it be possible to measure the time to create a random number?

best regards

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why don't you simply test it?

I once tested a Z diode circuit, and found it to create
a rather well-formed Gaussian distribution upon running
it frequently enough. With the 200x preamp, you get something
like 3 significant bits of noise. If anyone's interested, the
analysis (in a German-language forum) was published here:

http://www.mikrocontroller.net/forum/read-2-221331.html#222451

You'd need to run a similar test for your EEPROM write. I'm afraid
it might turn out to be too predictable for real randomness.

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Wulfinator83 wrote:

So I thought about the eeprom writing time! How constant is the length of this process?

Good idea, as the internal oscillator for EEPROM writing is independent of the main external crystal oscillator. This value may not vary much, but it's a start.

But note that at least Mega16 uses the 1MHz internal calibrated RC oscillator to time the programming, so if you run your AVR with the same internal RC oscillator, the programming should always take the same amount of CPU clock cycles. Also the internal RC should not be calibrated to over 10% of the rated value.

Some tricks also include reading timer counter value when user presses a button or some external event happens (time of some interrupt, random noise on ADC pin, time of incoming data over usart/spi/i2c).

- Jani

EDIT: If I am not mistaken, some AVRs can generate a Watchdog interrupt instead of resetting the AVR. Watchdog runs from a separate 1MHz RC oscillator.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is psuedo-random good enough? I use a LFSR (linear feedback shift register) for most needs.

Go electric!
Happy electric car owner / builder

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

> If I am not mistaken, some AVRs can generate a Watchdog interrupt
> instead of resetting the AVR.

All new AVRs can.

> Watchdog runs from a separate 1MHz RC oscillator.

From a separate 128 kHz oscillator, actually.

> Is psuedo-random good enough? I use a LFSR (linear feedback shift
> register) for most needs.

Which is what every good software library has behind the rand()
function. For true randomness (like security handling), it's not good
enough as it is predictable. The usual way is to seed the PRNG with a
true random value first.

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

maybe you could use triangle waveform generator made from squarewave and an intergrator made with opamp and convert it with ADC. this way chance of each number appearing should be the same and approximately equal 1/1024. also to increase randomization you could use RC components with as lowest temperature stability as possible

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There is a very good write up on using the avr wdt to generate random numbers in the following project:
http://tinyloader.kasperkp.dk/avr-wdt-hrng.zip

I can't remember where I stumbled onto it, but it's a good read even if you don't use exactly the same technique.

-carl

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The eeprom writing runs on an internal oscillator? Is it the same as the internal RC oscillator?
Because I'm using an ATTINY45 running on the RC osc. and this would explain why me eeprom measurement doesn't produce random numbers. :?
What I need is a software solution, because I don't have free pins! At the moment I have a look at the tiny loader project.
@dl8dtl: what is PRNG? Pseudo RNG?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

> What I need is a software solution, because I
> don't have free pins!

Unless your device has anything that will produce true randomness,
there's no software solution. So if you don't have free pins, you
need to research a solution that could re-use your existing
connections. (The only AVRs I've heard of that have a hardware
random-number generator are these top-secret secure AVRs.)

> what is PRNG?

A pseudo random number generator. Google would have easily told you...

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

what do you have attached to the pins? you might use them as a source for random values by adding, subtracting or multiplying their values with for example timer value

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mpopov23 wrote:
what do you have attached to the pins? you might use them as a source for random values by adding, subtracting or multiplying their values with for example timer value

At the moment a shift register and a bus!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Attach an external noise generator (through an ADC?) to the bus.

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The easiest way to generate pseudo random number is using a linear feedback shift register.The lfsr will produce a sequence of numbers which will repeat after 2^n-1 steps if it is a maximal length lfsr,the sequence produced has certain well understood properties which meani its not suitable for anything needing really very high quality randoness.A good starting point is here
http://www.ece.cmu.edu/~koopman/...
A reverse biased pn junction as has been discussed will produce pink noise with a 1/f power spectrum,however that can be used as the input to a hash function such as md4 and will then produce white noise.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Jez_smith wrote:
The easiest way to generate pseudo random number is using a linear feedback shift register.The lfsr will produce a sequence of numbers which will repeat after 2^n-1 steps if it is a maximal length lfsr,the sequence produced has certain well understood properties which meani its not suitable for anything needing really very high quality randoness.A good starting point is here
http://www.ece.cmu.edu/~koopman/...
A reverse biased pn junction as has been discussed will produce pink noise with a 1/f power spectrum,however that can be used as the input to a hash function such as md4 and will then produce white noise.

But the OP has no more pins available for any external devices (except on the bus), and yes, LFSRs are great pseudo-random sources, but it needs to be initialized with a random enough number too.

The AVR on the device is somehow programmed, by a PC maybe, so could the PC generate the random number into AVR when programming or if the device can communicate via serial port maybe PC can send serial numbers and random numbers to AVR?

- Jani

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The watchdog is driven by an independent 128kHz oscillator
Take a look at datasheet page 22.

So there is a source for random numbers. :D

Regards
Sebastian

Last Edited: Tue. Oct 31, 2006 - 06:22 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

And the paper given by CARL H. OTTs post above
shows how to use it !

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ossi, Carl: Note that I didn't test the internal oscillator (and said so in a big, fat bullet in the conclusion). I still think it works though, likely even better than with external clock.
The only thing I could fear is clock-lock, a situation where noise from one clock oscillator phase locks another. This, however, should be WORSE when running with external oscillator than when running with internal oscillator.

The zip is also linked from the avrfreaks project https://www.avrfreaks.net/index.php?module=Freaks%20Academy&func=viewItem&item_type=project&item_id=546.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i agree with dl8dtl. connect small noise generator to the bus and scan it with AD converter and use LSB of ADC value and shift it to left or right and repeat eight times to get random 8-byte value.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You can give a try to the Numerical C receipes book. It has a chapter dedicated to this kind of stuff. It's funny to read, free and accesible trhough a web page.

Guillem.

Guillem.
"Common sense is the least common of the senses" Anonymous.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

But even the best numerical recipe won't get you a random number.

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I agreee, Jörg. I always tought that the only randomness in the math world is when the teacher corrects my exams...

Guillem.

Guillem.
"Common sense is the least common of the senses" Anonymous.