Path: Home => AVR-EN => Applications => Random ATtiny13   Diese Seite in Deutsch: Flag DE Logo
Random colors 250*250 AVR applications

Random number generation with ATtiny13
Application and software for random numbers in assembler
There are many random number generators in the net, most of those are in C and use intransparent functions. Here is one in assembler that you can understand completely. And it is lean in size and very, very fast.

Random numbers with ATtiny13

To generate such a picture with 65.536 color dots, each colored from more than 17 million possible colors, you need a random generator. Well, not exactly: as I converted it from a bitmap to a gif file to save webspace and download time for the picture, it does not have more 256 different colors. But: still enough to impress you.

Random numbers are numbers that show no regularity and stem from the whole number spectrum (here: 8 bit or 256 numbers). That is done by mixing the bits in a seed (here: two bytes). Because that mixing is done with a limited number of controller instructions (here: three binary operations), the result is not a random series of numbers: at a certain point the generated row repeats (even if that repetition only occurs after many, many cycles). This is analyzed, described and discussed in Chapter 1.

We want to be able to view those generated random numbers. This is done here with a RGB LED, with their color shares red, green and blue modulated between 0 and 255. The three colors are displayed over a selected time share in a Pulse-width-modulated manner (PWM), here controlled by a piece of assembler software: the three colors are switched on at the beginning of a PWM cycle, and are switched off if their comparison value is reached. As this switching is done 70 times per second, the human eye only has the expression of a mixed color and does not see the fast switching. The necessary hardware for that, utilizing an ATtiny13, is described in Chapter 2, which also shows the software functions used.

For "real" random some more hardware is required. A noise generator would be an appropriate approach. Those should produce more randomeous events. Read more about how I failed with this effort in Chapter 3. Due to the tremendous failure in the previous section let's try some more reliable hardware: Why not use a sine wave oscillator as random source? If we sample its amplitude and use only the last bit of the 10 bit result, we should get random numbers. I analyzed this option deeper, constructed an RS232 transmitter that allows to shovel thousands of produced numbers to a PC to analyze those in depth, in Chapter 4.

16-bit randoms can be generated and their properties can be analyzed here. A powerful tool detects re-occurrences of quadrupletts in one million numbers.

Page top Calculation Display Noise generation Analysis sine wave Generation and analysis of 16-bit randoms


Praise, error reports, scolding and spam please via the comment page to me.

©2020 by http://www.avr-asm-tutorial.net