Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Random number generator in assembly code

Does anyone know how to code a 8 bit numbers to be randomly generated in assembly code?

I'm using ATmega8535 with Atmel AVR Assembler with the Debug of AVR Simulator. (AVR Studio 4)

Sorry i am new to this and any help would be appreciate Thanks

like image 891
Joe Cobain Avatar asked Oct 29 '25 20:10

Joe Cobain


1 Answers

It really depends on what you mean by random. If you just want a sequence of numbers that are predictable but have statistical randomness then the simplest to implement on a microcontroller is the linear feedback shift register. An example of an implementation in assembly on a PIC device can be seen here.

Variations with better cross-correlation properties are Gold-Codes which are a bit more complex but rely on the same principle. There are also a lot of other algorithms, but it really depends on what sort of statistical properties you require.

If you need something with a high level of entropy (i.e. can't be predicted) then a novel way is to use the device's ADC to sample the voltage on a reversed biased diode junction. The noise generated by this is a robust source of entropy. However, you need to be careful that you don't introduce any order into the system by accident so some care in the design is needed.

like image 144
Jon Avatar answered Oct 31 '25 11:10

Jon