Learn how to code for randomize functions, randomization, true random numbers generator.

Randomize Function, Randomization, True Random Number Generators, Source Code

By Ion Saliu, Founder of Randomness Programming

The opposite of true randomization is pseudo-random: Humans predict outcomes accurately.

Written on January 1, 2002 (2 WE); later updates.

Randomness or degree thereof is a lot more important than I thought previously. I always said that the Universe is the result of random interaction of forces. The differences are in the probabilities. No arguments there.

I am referring here to a down-to-earth form of randomness: random number generation in software.

I started years ago in this field. I posted previously on the topic. In 1985 I was working on a farm, in the same area I live now: South-Central Pennsylvania. Interesting farming! One of my colleagues had a home computer; I think it was a Vic-20. I was a computer buff myself, although did not possess a PC toy at that time. My colleague gave me the user's guide of his PC and asked me to write a program to generate lotto numbers! The booklet had a short presentation of the BASIC language built in the ROM chip.

Interestingly, the random function was hardware-based! The lotto program was ready in no time and we put it to work. The program was slow, although it was not using any lottery filtering. The lotto combinations generated that day had a very good statistical fluctuation. They either had no hits, or had two-three hits the following lotto drawing. Even if the program had no paid winners, I liked its performance.

It was after a few weeks that one of the lotto combinations had '5 of 6' winners! I had no hesitation in enrolling a correspondence course in computer programming. The course offered also a computer (a tiny Sinclair) – the main reason I enrolled. Then I saw a deeply discounted price of an Atari 800 XL personal computer. I was on my way — after buying that incredible piece of home computing!

The 64 KB Atari allowed me to introduce lotto filtering, albeit in a limited form. The main problem: the wonderful toy did not have a disk drive. I just couldn't find one. I even wrote to Atari Corporation. The disappointing answer was “product line discontinued”! Every time I wanted to run my lotto-6 program, I had to write it again, with all its lottery filters! It was painstaking! The workaround was to leave the computer on for days. I wanted it on for weeks, but it was not possible.

The electric bill was not a problem — the farm paid it! The consumption was negligible, nevertheless. The “problem” was an old chap, always in the mood of playing a practical joke. His name was Donald, an authentic joker. The old man was one of the owners of the farm. He had a garage right underneath my apartment. He would love to prank me.

The frequency of his joking followed sophisticated rules of...randomness! I wouldn't be able to “predict” them! He would simply interrupt the electric power in his garage and my apartment as well. I was screaming, because I had to rewrite a painstaking computer lottery program again and again... By the way, I also planted cantaloupes and raspberries in my front yard. Donald was the man in charge with mowing. He would also mow my cantaloupes and all my plants, randomly, of course! And he would laugh like crazy! Donald, may Almighty Number grant your atoms the most righteous flow in this comic Cosmos!

On February 12, 1986 WEB, my Atari 800 XL shocked the foundation of the RandomHouse. The lotto program was running — uninterruptedly — for days. I stopped the program and selected 12-number lotto combinations from the end of the run. The very last 12-number combination started with the 6 winners drawn in the PA lotto 6/40! The jackpot was over 3 million but we didn't play. I posted on the sad story last year.

The point I want to make here is the randomizing feature used by the early personal computers. They came bundled with the BASIC language. The programming language was not on a disk (software-based) but built-in ROM (hardware-based). I don't know the exact technical details. I read that the random function communicated directly with the chip quartz. I think it read directly the quartz frequency and used the value as a so-called random seed. The advantage of that technique is a wider variation in the seed value.

Microsoft BASIC took control of the programming language in the early 1980's. It was bundled with IBM PC. The program was no longer in ROM, but on a disk. DOS was a solid programming platform, no doubt about that. The problem, from my perspective, was the introduction of software-based randomization. Some say it is pseudo-randomness. The software generates “random” numbers based on a “seed”, usually the timer. The timer counts the number of seconds since mid-night: from 0 to 86400.

I noticed some anomalies in my ActiveX control that generated random lotto combinations based on the timer. They showed clumpness quite often. That feature is a common fact at the blackjack tables when the game starts with a brand new deck of cards. The degree of randomness is very low, because the casino dealer doesn't have enough time to shuffle the card deck thoroughly. The randomness is low, because it becomes predictable more often than not what streaks follow. A keen blackjack player will notice long streaks of like-cards: either low or high cards. The longer the game goes, the higher the randomness will become.

I compared also the roulette spins generated by my ActiveX control (created in Visual Basic) with real-life spins. I also noticed more clumpness in the software-generated roulette spins. I had only an explanation: the timer seed does not offer enough randomness. There are 86,400 seconds in a day. The variation is just too low by computer standards!

I came up with a new randomizing function I will show at the end. Basically, it uses the date as a number. The function plays randomly with that number and the timer. The variation is far wider: from hundreds of thousands to billions. Now, there is something I can improve on. The new seed took very high values on December 31 (yesterday), but lower today, January 1st. I can think of other randomly varying...variables, such free memory and free disk space. The drawback is an increase in application size.

The new random function is implemented in the latest version of the ActiveX control. I like the results. I can see the results fall very consistently within the ranges of the normal probability rule. The easiest way to verify is the coin-tossing game. Write a simple text file named GAMES.1. The file has one line only:
Heads, Tails
(press Enter to end the line!)

Input that file in the “U.S. Bet” function. Go to the end of file and see the statistical report. The binomial standard deviation in coin tossing is 5 in 100 trials.

Ion Saliu is the founder of true random number programming by creating randomization functions.

Here is the source code of the new randomizing function, TheSeeder. You can set the random seed by a call to the function:
TheSeed = TheSeeder()
Randomize TheSeed

I'll tell you a little-known secret here. There is no … secret that the lotto combinations randomly generated will not hit with the first seed, or the first few randomizing seeds. Therefore, the more seeds the random-number generator uses, the higher the degree of certainty of getting closer to the winning lotto combonation. Thusly, let's generate several randomization seeds before generating random numbers (as in random lotto combosnations)! I am using here the number of repetitions somehow related to the golden number PHI:

   TheSeed = TheSeeder ()
   RANDOMIZE TheSeed
     FOR I = 1 TO RND(1, 1618)
   TheSeed = TheSeeder ()
     NEXT I
   RANDOMIZE TheSeed


'----- highly randomized seed generation: from hundreds of thousands, to millions to billions
FUNCTION TheSeeder() AS QUAD
DIM TheSeed AS QUAD
DIM Seed1 AS QUAD
DIM Seed2 AS QUAD
DIM This AS STRING
DIM Num1 AS DWORD
DIM Num2 AS DWORD
DIM Num3 AS DWORD

RANDOMIZE (TIMER + CLNG(RND*TIMER+1) + CLNG(RND*TIMER+1) * CLNG(RND*TIMER+1))

' --- use system date and time to get seeds very different from day to day
This = DATE$

Num1 = VAL(MID$(This, 1, 2))
Num2 = VAL(MID$(This, 4, 2))
Num3 = VAL(MID$(This, 7, 4))

Seed1 = (CQUD(RND * Num1) + 1) * (CQUD(RND * Num2 + 2) * (CQUD(RND * Num3 + 3) + 4)) 'Timer
Seed2 = (CQUD(RND * Seed1) + 5) * Seed1
TheSeed = Seed2 + (CQUD(RND * TIMER + 1) * CQUD(RND * Num3 + Num2))

TheSeeder = TheSeed

END FUNCTION

The best randomization function is incorporated in the latest random number generator. The source code in the BASIC programming language is still free. The software also mimics real-life lottery drawings: unsorted random numbers.

Download compiled program of Basic random number generator with true randomizing function.

The randomize function based on DATE is key to true random numbers generators.

Resources in Theory of Probability, Mathematics, Statistics, Combinatorics, Software.
See a comprehensive directory of the pages and materials on the subject of theory of probability, mathematics, statistics, combinatorics, plus software.

  • Theory of Probability: Best introduction, formulae, algorithms, software.

    Randomization is art of scientific philosophy, science of philosophical art of skills, creativity.

    Thanks for visiting best site in random numbers generating, programming with randomizing functions.

    | Home | Search | New Writings | Odds, Generator | Contents | Forums | Sitemap |

    Using the date and time creates a truly random seed to be used by computers instead of Timer.