Random Number Generator

From OSDev.wiki
Revision as of 21:55, 16 October 2010 by osdev>Mariuszp (New page: = Random Number Generator = Random number generators can be implemented in lots of different ways. This article explains some of them. == Fibonacci random number == My OS uses a special...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Random Number Generator

Random number generators can be implemented in lots of different ways. This article explains some of them.

Fibonacci random number

My OS uses a special "remake" of the Fibonacci sequence to generate random numbers. This is done by having 4 "seeds", which start off as really weird values (e.g. 45, 80, 22, 32).

I implemented a seed() function which adds a new seed to the end of the sequence, and erases the first one (the seeds are referred to as A, B, C and D). The rand() function just returns the sum of the seeds, and calls seed() with the result.