Random numbers are useful for a wide variety of situations, such as generating data encryption keys, simulating and modeling complex phenomena and selecting random samples from larger data sets.

Random numbers have also been used aesthetically, for example, in literature and music and for games and bets.

However, it is common for computer users not to correctly understand the “random numbers generator” of their system and the “random numbers” it produces, and in fact that it works with pseudo-aleatoity.

Randomness Concepts

Let’s work a little the conceptual basis on sequence and random numbers - randomness, and pseudo-randomness.

With the advent of computers, programmers recognized the need for a means of introducing randomness into a computer program. However, as surprising as it may seem, it is difficult to make a computer do something by chance.

A computer follows its instructions blindly and is therefore totally predictable (a computer that does not follow your instructions in this way is damaged).

There are two main approaches to generate random numbers using a computer: Pseudo-random numbers generators (PRNGs) and Truly random numbers generators (TRNGs). The approaches have quite different characteristics and each has its pros and cons.

The numbers calculated by a computer through a deterministic process cannot, by definition, be random.

Given the knowledge of the algorithm used to create the numbers and their internal state, you can predict all numbers returned by subsequent calls to the algorithm, while with genuinely random numbers, knowledge of a number or an arbitrarily long sequence of numbers is uselessany way in the forecast of the next number to be generated.

“Random” numbers generated by computer are more appropriately called numbers pseudo-ramdom and pseudo-random sequences of such numbers.

A variety of intelligent algorithms has been developed to generate sequences of numbers that pass on all statistical tests used to distinguish random sequences from those that contain some standard or internal order.

Random number

In mathematics and statistics, a random number is pseudo-random or a number generated for, or part of, a set that displays statistical randomness.

When discussing unique numbers, a random number is one that is taken from a possible set of values, each of which is equally likely, ie a uniform distribution.

The definition of random sequence deepens and clarifies:

Random sequence

When discussing a sequence of random numbers, each number drawn must be statistically independent of others.

The concept of random sequence is essential in the theory of probability and statistics. For statistics, a random number is a number that belongs to a numerical series and cannot be foreseen from the previous members of the series.

The concept of random number is a concept related to the numerical series to which the number belongs. One number may be random in a numerical series and not random in another.

In theoretical concepts, the theory of axiomatic probability deliberately prevents the definition of a random sequence. The theory of traditional probability does not affirm whether a specific sequence is random, but usually proceeds discussing the properties of random variables and stochastic sequences assuming some definition of randomness.

Generation of sequences and random numbers

Generation of random numbers is a process that generates a sequence of numbers or symbols that cannot be reasonably predicted better than by a random chance.

They can be generated by truly random hardware random numbers generators (HRGS), which generate random numbers as a function of the current value of some attribute of the physical environment that is constantly changing in a way that is virtually impossible to model, or Pseudo-random numbers generator (PRNGs), which generate numbers that seem random but are really deterministic and can be reproduced if the state of PRNG is known.

Several randomness applications have led to the development of several different methods to generate random data, some of which existed since ancient times, among whose rows are known “classic” examples, including data release, currency launch, letters of letters from Playing, the use of militar stalks (for guessing) at I Ching, as well as numerous other techniques.

Due to the mechanical nature of these techniques, generating large amounts of random enough numbers (important in statistics) required a lot of work and time. Thus, the results were sometimes collected and distributed as random numbers tables.

There are several computational methods for generating pseudo-aleatory numbers. Everyone falls short of the purpose of true randomness, although they can, with variable success, some of the statistical tests of randomness designed to measure how unpredictable their results are (that is, to what degree their standards are discerned).

This usually makes them unusable for applications such as encryption. However, carefully projected and encrypted pseudo-aleatary numbers generators (CSPRNGs) also exist, with special features designed specifically for encryption use.

Pseudo-ramdom numbers generators (PRNGs)

Like the word pseudo suggests, pseudo-random numbers are not exactly random as you can expect, at least not the same way you may be used to playing dice or lottery tickets.

Essentially, PRGS are algorithms that use mathematical formulas or simply pre-calculated tables to produce numbers that seem random.A good example of PRNG is the Linear congruential method.

A lot of research and investment was done in theory about pseudo-aleatory numbers, and modern algorithms to generate them are so good that numbers really look like they were truly random.

The basic difference between PRNGs and TRNGs is easy to understand when comparing computer -generated random numbers to the results of a data.

Considering that PRNGs generate random numbers using mathematical formulas or pre-calculated lists, an equivalent method would be someone to play many times and write down the results.Whenever you then made a data move, you would get the next result on the list.The results seem random, but they are really predetermined.

TRNGs work making a computer really dice the data or, more commonly, use some easier physical phenomenon to connect to a computer than a data.

PRNGs are efficient, that is, can generate many numbers in a short time, and deterministic, which means that a certain sequence of numbers can be reproduced at a later date if the sequence starting point is known (seed).

Efficiency is a good feature if your application needs a lot of large amounts of numbers, and determinism is useful if you need to reproduce the same sequence of numbers again in a future stage or context.

Usually PRNGs are also periodic, that is, they are finite. This means that the sequence will eventually repeat itself. Although this is not always desirable, modern PRNGs have such a long period that it can be ignored for most practical application purposes.

For all these characteristics, PRNGs are suitable for applications where many numbers are needed and where it is useful that the same sequence can be easily reproduced.

Popular examples of such applications are simulation and modeling systems.

PRNGs, however, are not suitable for applications where numbers need to be truly unpredictable, such as encryption systems, data games or other gambling.

It is important to understand that while there are good PRNG algorithms, they are not always used because it is easy to get undesirable surprises.

See the example of the popular web programming language PHP:

If you use PHP in GNU/Linux operating system distributions, you are likely to be satisfied with random numbers generated by language.

However, if you use PHP for Microsoft Windows, you will probably find that your random numbers not generated as expected, as shown in this Visual Analysis of 2008.

Another example is from 2002, when a researcher reported that PRNG in MacOS was not good enough for scientific simulation of virus infections.

I am not stating that these situations remain to this day, especially considering the evolution of operating systems and programming languages.The main question is disliked, even if a PRNG meets the needs of your application, you should read carefully evaluated not to receive out of expected results for your application.

True Random Numbers Generators (TRNGs)

Compared to PRNG, TRNGs guarantee randomness using physical phenomena and introduce it to a computer.You can imagine this as a rolling data connected to a computer.

However, usually physical phenomena is used easier to connect to a computer than a data:-D.

The physical phenomenon can be very simple, such as small variations in someone’s mouse movements or the amount of time between the pressures made on a keyboard keys when entering.

In practice, however, you should be careful about the phenomenon and source you choose.For example, it can be complicated to use key pressures this way, because key pressures are often stored in buffer by the computer operating system, which means several key pressures are collected before they are sent to the program that is waiting for bythey.For a program that awaits key pressures, it will seem that the keys have been pressed almost simultaneously and there may not be much randomness in this process.

But there are many other ways to get true randomness on your computer.

A very good physical phenomenon to use is a radioactive source. Points at a time when a radioactive source decays are completely unpredictable and can be easily detected and fed on a computer, avoiding any buffer mechanisms in the operating system.

Fourmilab Hotbits Service in Switzerland is an excellent example of a random numbers generator that uses this technique.

Another adequate physical phenomenon is the The atmospheric rise, very easy to capture with a normal radio.This is the approach used by RANDOM.org.

You can also use the background noise of an office or laboratory, but should be aware of the standards.The fan of your computer can contribute to background noise but, as the fan is a rotary device, it is likely that the noise it produces is not as random as atmospheric noise.

Undoubtedly, the visually more interesting approach is Lavarand generator, which was built by Silicon Graphics and used photos of lamp lamps to generate random numbers.

The project is no longer operational, but one of its inventors remains work without the lamp lamps on the Lavand website.

Another approach is Java Entropypool, which brings together random bits from a variety of sources, including hotbits and random.org, as well as web page accesses received by the entropypool server itself.

Regardless of which physical phenomenon is used, the process of generating real random numbers involves identifying small unpredictable changes in the data.For example, Hotbits uses minor variations in delay between occurrences of radioactive decay, and random.org uses small variations in the amplitude of atmospheric noise.

As for the characteristics of TRNGs, they are quite different from PRNG.

Firstly, TRNGs are usually inefficient compared to PRNG, taking much longer to produce numbers.They are also non -deterministic, which means that a given sequence of numbers cannot be reproduced, although the same sequence can, of course, occur several times by chance.Finally, TRNGs have no periodization, it is possible to generate an infinite sequence of random numbers.

Random numbers generation programs

Then I present a list of internet services, websites and libraries (programming packages) or material with programming in programming languages for generating random numbers or pseudo-aleataries.

The first part presents a program to test random sequences, followed by a list of software and internet services for random numbers, ending with tutorials and examples of how to generate random numbers in programming languages such as C, PHP, Python, Java, JavaScript, among others.

Tests for random numbers

Testing sequences of pseudo-random bytes

You can use the programa ENT (A Pseudorandom Number Sequence Test Program) To apply tests to bytes sequences and report how random they seem to be.

By executing it in data generated by a high quality pseudo-sequence generator, you will see that it generates data that is indistinguishable from a randomly chosen bytes sequence.Indistinguishable but not genuinely random.

Random numbers generators

Software and services resources for generating sequences and random numbers:


RANDOM.ORG It offers true random numbers to anyone on the internet.The randomness comes from atmospheric noise, which for many purposes is better than pseudo-aleatory algorithms normally used in computer programs.People use random.org to make sweepstakes, lotteries and sweepstakes, to conduct online games, for scientific applications and to art and music.The service has existed since 1998 and was built by Dr.Mads Haahr of the Trinity College Computer Science and Statistics School, Dublin, Ireland.Today, Random.org is operated by Randomness and Integrity Services Ltd.

Free services

The site offers a variety of free services separated by categories:

Games and Lotteries
  • Quick Pick Lottery is perhaps the most popular on the internet, with over 280 lotteries
  • Keno Quick Pick For the popular game played in many countries
  • Coin Flipper will give you face or crown in many coins
  • Dice roller do exactly what it says: launches data
  • Playing Card Shuffer will take cards from several shuffled decks
  • Birdie Fund Generator will create bird holes in golf courses
  • The integers generator creates random numbers at configurable intervals
  • The sequence generator will randomize an entire sequence of your choice
  • Gerator of integer sets makes sets of unspoken integers
  • Gaussian Generator Creates random numbers to adjust to a normal distribution
  • The decimal fraction generator creates numbers in the range [0.1] with configurable decimal places
  • Bytes random rawlings are useful for many cryptographic purposes
Lists, strings and maps
  • List Randomizer will randomize a list of everything you have (names, phone numbers, etc.)
  • The _Maword Generator creates safe passwords for your Wi-Fi or Extra Gmail account
  • Clock Time Generator will choose random times of the day
  • Calendar Date Generator will choose random days over almost three and a half millennia
  • The Geographic Coordinate Generator will choose a random location on the surface of our planet
  • Bitmaps in black and white
  • The hexadecimal color code generator_ will choose color codes, for example, to use as web colors
  • Pre-Gerado Rooms contain large amounts of random bits for download
  • Pure White Audio Noise for composition or just to test your audio equipment
  • Jazz scale to practice improvisation for jazz guitar students
  • The Prosa short randomly generated by Samuel Beckett
  • Randomizer of sequence of protein of DNA (in Bio-Web)

O RANDOM.ORG ainda possui widgets para sites e API para o desenvolvimento de aplicações que necessitam de geração de números verdadeiramente aleatórios como jogos.


HotBits It is an Internet resource that brings genuine random numbers, generated by a process fundamentally governed by the uncertainty inherent in the laws of nature quantum mechanics, directly to your computer in a variety of ways.

Hotbits are generated synchronizing successive pairs of radioactive decay detected by a geiger-müller tube connected to a computer.

You request your portion of hotbits by filling out a request form specifying how many random bytes you want and in which format they want them to be delivered. Your request is relayed to the HotBits server, which sends the random bytes back to you on the web.

Because hotbits generation hardware produces data at a modest rate (about 100 bytes per second), requests are filled from a pre-constructed hotbit inventory.

Since random bytes are delivered to you, they are immediately discarded - the same data will never be sent to any other user and no records are kept from the data in this or any other site - of course, if you are using the random data to Encryption or other security -related applications, cannot be sure that the service is not keeping a copy. They claim not that.

An alternative to download hotbits for later use is provided by Randomx Package for Java. A program developed with Randomx can select from a variety of pseudo-sequence generators or genuine hotbits random data obtained on demand on the internet.

List of tutorials to program the generation of random numbers

Tutorial for Language C

Tutorial for generation of random numbers in C It is an article that demonstrates how to generate randomic numbers using the C language and the rand function. This article can be used as a base for generation also in C ++.