Generating Random Numbers

The world is an unpredictable place. Even more so than Mr Gump's box of choclates. It would be terribly boring of there was only 1 shape of tree in the world, and every one looked the same. Likewise, it gets boring when you're playing games and the computer players, aliens, whatever, do the same things every time you play it. This is why it is useful to have a random number generator in your programs.
However there is something to note here. There is no such thing as random, (except maybe on the quantum level). Generating random numbers, therefore, has alwaws been a bit of a problem. The random numbers generated by the random number function in your programming language (if it has such a thing) are not really random at all. They are infact pseudo-random. They are generated using a very complicated formula that takes a number, and returns another. The returned number should, hopefully, be very difficult for a human to predict. Beacuse it's a function, it will always return the same number when passed the same number. You usually don't see all this number passing going on, because the function passes its last generated number to itself to generate a new number when it's asked for. Anyway, all this is irrelevant really. what i'm saying is that random number generators are often quite slow. What I shall present here is a random number generator that uses just ADDs, and ANDs and a few IFs. It is really quite fast. I have a feeling that it stablises after a few hundred thousand iterations, but thats not really a problem. It'll give you quite a few random numbers before you need to reset it.
You can try fiddling around with the numbers and stuff, to see if you can get it any better. Its just a quick one I knocked up in a couple of mins, so I haven't really tested it very extensively. I had it incrementing the colour of random pixels on the screen and it seemed to give a very even distridution on numbers across its range of 0 to 255. Don't ask me why/how it works, I have no idea, its just chaotic or something.

here it is written in BASIC:

and for those people who want to generate numbers at speed, here it is again in 086 assembler. And not a MUL or DIV in sight.

and AL now contains a random number between 0 and 255

Of course, this system suffers from the same problem that it will produce the same set of random numbers every time you start it. A good way to overcome this, is to set the values of v1, v2 and v3, based on the numbers of hours mins and seconds in the computer's timer when the program starts. This way, the generator will always start with different values, and so will produce different sets of random numbers.