Random order of numbers. Excel Random Number Generator in Functions and Data Analysis

  • Tutorial

Have you ever wondered how Math.random() works? What is a random number and how is it obtained? Imagine an interview question - write your random number generator in a couple of lines of code. So, what is it, an accident and is it possible to predict it?

I am very fascinated by various IT puzzles and tasks, and the random number generator is one of these tasks. Usually in my telegram channel I sort out all sorts of puzzles and different tasks from interviews. The random number generator problem has gained great popularity and I wanted to perpetuate it in the depths of one of the authoritative sources of information - that is, here on Habré.

This material will be useful to all those front-end and Node.js developers who are on the cutting edge of technology and want to get into a blockchain project/startup where questions about security and cryptography are at least basic level, they even ask front-end developers.

Pseudo-random number generator and random number generator

In order to get something random, we need a source of entropy, a source of some chaos from which we will use to generate randomness.

This source is used to accumulate entropy and then obtain from it an initial value (seed), which is necessary for random number generators (RNG) to generate random numbers.

The Pseudo-Random Number Generator uses a single initial value, hence its pseudo-randomness, while the Random Number Generator always generates a random number, having at the beginning a high-quality random variable, which is taken from various sources of entropy.

Entropy is a measure of disorder. Information entropy is a measure of the uncertainty or unpredictability of information.
It turns out that in order to create a pseudo-random sequence we need an algorithm that will generate a certain sequence based on a certain formula. But such a sequence can be predicted. However, let's imagine how we could write our own random number generator if we didn't have Math.random()

PRNG has some algorithm that can be reproduced.
RNG is the process of obtaining numbers entirely from some kind of noise, the ability to calculate which tends to zero. At the same time, the RNG has certain algorithms for equalizing the distribution.

We come up with our own PRNG algorithm

Pseudorandom number generator (PRNG) is an algorithm that generates a sequence of numbers whose elements are almost independent of each other and obey a given distribution (usually uniform).
We can take a sequence of some numbers and take the modulus of the number from them. The simplest example that comes to mind. We need to think about which sequence to take and the module from what. If you just directly from 0 to N and modulus 2, you get a generator of 1 and 0:

Function* rand() ( const n = 100; const mod = 2; let i = 0; while (true) ( ​​yield i % mod; if (i++ > n) i = 0; ) ) let i = 0; for (let x of rand()) ( if (i++ > 100) break; console.log(x); )
This function generates the sequence 01010101010101... and it cannot even be called pseudo-random. For a generator to be random, it must pass the next bit test. But we don’t have such a task. Nevertheless, even without any tests we can predict the following sequence, which means that such an algorithm does not work head-on, but we are in the right direction.

What if we take some well-known but non-linear sequence, for example the number PI. And as the value for the module we will take not 2, but something else. You can even think about the changing value of the module. The sequence of digits in Pi is considered random. The generator can operate using Pi numbers starting from some unknown point. An example of such an algorithm, with a PI-based sequence and a variable module:

Const vector = [...Math.PI.toFixed(48).replace(".","")]; function* rand() ( for (let i=3; i<1000; i++) { if (i >99) i = 2; for (let n=0; n But in JS, the PI number can only be displayed up to 48 digits and no more. Therefore, it is still easy to predict such a sequence, and each run of such a generator will always produce the same numbers. But our generator has already started showing numbers from 0 to 9.

We got a generator of numbers from 0 to 9, but the distribution is very uneven and it will generate the same sequence every time.

We can take not the number Pi, but time in numerical representation and consider this number as a sequence of numbers, and in order to ensure that the sequence does not repeat each time, we will read it from the end. In total, our algorithm for our PRNG will look like this:

Function* rand() ( let newNumVector = () => [...(+new Date)+""].reverse(); let vector = newNumVector(); let i=2; while (true) ( ​​if ( i++ > 99) i = 2; let n=-1; while (++n< vector.length) yield (vector[n] % i); vector = newNumVector(); } } // TEST: let i = 0; for (let x of rand()) { if (i++ >100) break; console.log(x)
This already looks like a pseudo-random number generator. And the same Math.random() is a PRNG, we’ll talk about it a little later. Moreover, each time we get a different first number.

Actually on these simple examples You can understand how more complex random number generators work. And there are even ready-made algorithms. As an example, let’s look at one of them — this is the Linear Congruent PRNG (LCPRNG).

Linear congruent PRNG

Linear congruent PRNG (LCPRNG) is a common method for generating pseudorandom numbers. It is not cryptographically strong. This method consists of calculating the terms of a linear recurrent sequence modulo some natural number m, given by the formula. The resulting sequence depends on the choice of starting number — i.e. seed. At different meanings seed produces different sequences of random numbers. An example of implementing such an algorithm in JavaScript:

Const a = 45; const c = 21; const m = 67; var seed = 2; const rand = () => seed = (a * seed + c) % m; for(let i=0; i<30; i++) console.log(rand())
Many programming languages ​​use LCPRNG (but not exactly this algorithm(!)).

As mentioned above, such a sequence can be predicted. So why do we need PRNG? If we talk about security, then PRNG is a problem. If we talk about other tasks, then these properties can be a plus. For example, for various special effects and graphics animations, you may need to frequently call random. And this is where the distribution of meanings and performance are important! Secure algorithms cannot boast of speed.

Another property is reproducibility. Some implementations allow you to specify a seed, and this is very useful if the sequence must be repeated. Reproduction is needed in tests, for example. And there are many other things that do not require a secure RNG.

How Math.random() works

The Math.random() method returns a pseudo-random floating point number from the range = crypto.getRandomValues(new Uint8Array(1)); console.log(rvalue)
But, unlike the Math.random() PRNG, this method is very resource-intensive. The fact is that this generator uses system calls in the OS to gain access to entropy sources (mac address, CPU, temperature, etc...).

The random number generator for lottery tickets is provided free of charge in an “as is” format. The developer does not bear any responsibility for material and non-material losses of script users. You may use this service at your own risk. However, you definitely don’t want to take risks :-).

Random numbers for online lottery tickets

This software (RNG in JS) is a pseudo-random number generator implemented using the Javascript programming language. The generator produces a uniform distribution of random numbers.

This allows you to knock out a “wedge with a wedge” on the RNG with a uniform distribution from the lottery company to respond with random numbers with a uniform distribution. This approach eliminates the subjectivity of the player, since people have certain preferences in choosing numbers and numbers (Birthdays of relatives, memorable dates, years, etc.), which affect the selection of numbers manually.

The free tool helps players select random numbers for lotteries. The random number generator script has a set of pre-configured modes for Gosloto 5 out of 36, 6 out of 45, 7 out of 49, 4 out of 20, Sportloto 6 out of 49. You can select a random number generation mode with free settings for other lottery options.

Lottery winning predictions

A random number generator with uniform distribution can serve as a horoscope for a lottery draw, although the probability that the forecast will come true is low. But still, using a random number generator has a good probability of winning compared to many other lottery strategies and additionally frees you from the pain of difficult selection of lucky numbers and combinations. For my part, I do not advise you to give in to the temptation and buy paid forecasts; it is better to spend this money on a textbook on combinatorics. You can learn a lot of interesting things from it, for example, the probability of winning the jackpot in Gosloto is 5 out of 36 1 To 376 992 . And the probability of getting the minimum prize by guessing 2 numbers is 1 To 8 . The forecast based on our RNG has the same probabilities of winning.

There are requests on the Internet for random numbers for the lottery, taking into account past draws. But provided that the lottery uses RNG with a uniform distribution and the probability of getting one or another combination does not depend on each draw, then it is pointless to try to take into account the results of past draws. And this is quite logical, since it is not profitable for lottery companies to allow participants to use simple methods to increase the likelihood of winning.

There is often talk that lottery organizers are rigging the results. But in fact, this makes no sense, even, on the contrary, if lottery companies influenced the results of the lottery, then it would be possible to find a winning strategy, but so far no one has succeeded. Therefore, it is very profitable for lottery organizers that the balls fall out with uniform probability. By the way, the estimated return on lottery 5 out of 36 is 34.7%. Thus, the lottery company retains 65.3% of the proceeds from ticket sales, part of the funds (usually half) is allocated to the formation of the jackpot, the rest of the money goes to organizational expenses, advertising and the company’s net profit. Circulation statistics perfectly confirm these figures.

Hence the conclusion - do not buy meaningless forecasts, use a free random number generator, take care of your nerves. Let our random numbers become your lucky numbers. Have a good mood and have a great day!

We have a sequence of numbers consisting of practically independent elements that obey a given distribution. As a rule, uniform distribution.

You can generate random numbers in Excel in different ways and ways. Let's consider only the best of them.

Random Number Function in Excel

  1. The RAND function returns a random, uniformly distributed real number. It will be less than 1, greater than or equal to 0.
  2. The RANDBETWEEN function returns a random integer.

Let's look at their use with examples.

Sampling random numbers using RAND

This function requires no arguments (RAND()).

To generate a random real number in the range from 1 to 5, for example, use the following formula: =RAND()*(5-1)+1.

The returned random number is distributed uniformly over the interval.

Each time the worksheet is calculated or the value in any cell in the worksheet changes, a new random number is returned. If you want to save the generated population, you can replace the formula with its value.

  1. Click on the cell with a random number.
  2. In the formula bar, select the formula.
  3. Press F9. AND ENTER.

Let's check the uniformity of the distribution of random numbers from the first sample using a distribution histogram.


The range of vertical values ​​is frequency. Horizontal - “pockets”.



RANDBETWEEN function

The syntax for the RANDBETWEEN function is (lower bound; upper bound). The first argument must be less than the second. Otherwise the function will throw an error. The boundaries are assumed to be integers. The formula discards the fractional part.

Example of using the function:

Random numbers with precision 0.1 and 0.01:

How to make a random number generator in Excel

Let's make a random number generator that generates a value from a certain range. We use a formula like: =INDEX(A1:A10,INTEGER(RAND()*10)+1).

Let's make a random number generator in the range from 0 to 100 in steps of 10.

You need to select 2 random ones from the list of text values. Using the RAND function, we compare text values ​​in the range A1:A7 with random numbers.

Let's use the INDEX function to select two random text values ​​from the original list.

To select one random value from the list, use the following formula: =INDEX(A1:A7,RANDBETWEEN(1,COUNT(A1:A7))).

Normal distribution random number generator

The RAND and RANDBETWEEN functions produce random numbers with a uniform distribution. Any value with the same probability can fall into the lower limit of the requested range and into the upper one. This results in a huge spread from the target value.

A normal distribution implies that most of the generated numbers are close to the target number. Let's adjust the RANDBETWEEN formula and create a data array with a normal distribution.

The cost of product X is 100 rubles. The entire batch produced follows a normal distribution. A random variable also follows a normal probability distribution.

Under such conditions, the average value of the range is 100 rubles. Let's generate an array and build a graph with a normal distribution with a standard deviation of 1.5 rubles.

We use the function: =NORMINV(RAND();100;1.5).

Excel calculated which values ​​were within the probability range. Since the probability of producing a product with a cost of 100 rubles is maximum, the formula shows values ​​close to 100 more often than others.

Let's move on to plotting the graph. First you need to create a table with categories. To do this, we divide the array into periods:

Based on the data obtained, we will be able to generate a diagram with a normal distribution. The value axis is the number of variables in the interval, the category axis is periods.

Please help the service with one click: Tell your friends about the generator!

Online number generator in 1 click

The random number generator, which is presented on our website, is very convenient. For example, it can be used in sweepstakes and lotteries to determine the winner. The winners are determined in this way: the program produces one or more numbers in any range specified by you. Fraudulent results can be immediately ruled out. And thanks to this, the winner is determined by an honest choice.

Sometimes it is necessary to obtain a certain number of random numbers at once. For example, you want to fill out a “4 out of 35” lottery ticket, trusting to chance. You can check: if you toss a coin 32 times, what is the probability that 10 reverses will appear in a row (heads/tails may well be assigned the numbers 0 and 1)?

Random number online video instruction - randomizer

Our number generator is very easy to use. It does not require downloading a program to your computer - it can be used online. To get the number you need, you need to set the range of random numbers, the quantity and, if desired, the number separator and eliminate repetitions.

To generate random numbers in a specific frequency range:

  • Select a range;
  • Specify the number of random numbers;
  • The “Number separator” function serves for the beauty and convenience of their display;
  • If necessary, enable/disable repetitions using the checkbox;
  • Click the "Generate" button.

As a result, you will receive random numbers in a given range. The result of the number generator can be copied or sent by e-mail. It would be best to take a screenshot or video of this generation process. Our randomizer will solve any of your problems!

It is an obvious fact that luck plays an important role in any undertaking. But when playing the lottery, you need to understand that fortune is the only factor on which the fulfillment of your dreams depends. In most lotteries, to get the jackpot you just need to guess certain numbers in a certain range. In this case, the one presented on our website can help.

We offer to try a simple generator for free, which can completely eliminate the influence of the human factor and increase your chance of winning. We also present the best and most functional, but simple generators, as well as services that can predict winning combinations of numbers based on special analysis algorithms.

If you want to try your luck in one of the popular lotteries (4 out of 20, 5 out of 36, 6 out of 45), but don’t know what numbers can increase your probability of winning, then we can help. Next we present to your attention review of the TOP 5 most functional, but at the same time easy-to-use lottery number generators with many additional functions and capabilities.

First, let's look at the main criteria of the list.:

TOP 1 - Number generator GSgen.RU


Description: The built-in software is implemented in the Javascript programming language and is a pseudo-random number generator. Evenly distributes random numbers, thereby eliminating the subjective perception of players, which influences manual selection.

Advantages: The RNG script allows you to select lucky numbers for Gosloto (and not only) of various variations from preset modes. There is the possibility of individual settings for other types of lotteries. Available for free use.

Flaws: There is no way to enter exclusion numbers that you don’t want to see, you can’t get several combinations at once and get a link to the finished result.

TOP 2 – Soft-Arhiv Generator


Description: Another service for generating SP for Russian lotteries. Just select the required combination and get the finished result. You don't need any additional software to use it, as it works great online.

Advantages: Has a simple, clear form to fill out and get results. The ability to select a ready-made lottery type, generation settings allows you to include exceptions and the number of required combinations make the service very convenient to use. Also completely free functionality.

TOP 3 - RNG: Calculator888


Description: Calculator888 is in honorable third place among the services under consideration. Like the previous options, it allows you to get the required number of numbers without much effort. Even a novice network user can use the random number generator, as everything is intuitive.

Advantages: Extensive settings will allow you to generate the required number of numbers, set their range, and also determine input options. In addition, unlike previous services, it allows you to get a link to the result. Completely free.

Flaws: The disadvantages include the lack of a choice of ready-made lottery types, which forces you to create the task yourself. You cannot introduce exceptions and get several combinations at once. Accounting of past circulations is also not carried out.

Number generators based on past draws

It is worth drawing your attention to the fact that there are special services that can predict lucky numbers on which you need to bet. Their creators assure users that the analysis and presentation of results is carried out on the basis of the results of the draws, the use probability theory and other mathematical calculations.

However, you should not believe in this unconditionally. We definitely don’t believe in this and believe that any of these services are ones that randomly produce results similar to any other RNG.

However, you can check this yourself. Below we present two more services that provide the ability to select results for state lotto, Viking lotto, keno, sports lotto, etc. taking into account their past circulations. The functionality of some of them is paid.

Let us draw your attention to the fact that you should not pay money for a paid forecast, since this is just money down the drain for combinations that any other free service can produce. So, the continuation of the best services for generation, taking into account the analysis of past circulations:

TOP 4 - RNG taking into account circulations: Fortunablog


Description: According to the developer, the script is capable of not only issuing digital combinations at random, but also analyzes previously dropped balls based on a number of algorithms and probability theory. It is also stated that the purpose of the generator is to select a combination for the jackpot.

Advantages: There are two preset lottery types from which you can try your luck in selecting. However, the main advantage is positioned as taking into account the results of past circulations and, importantly, free use.

TOP 5 - Generator for lottery taking into account draws: Igraivloto


Description: The presented service allows you to get combinations of the most likely winning combinations. The principle of operation is similar to the previous options under consideration, with the exception of certain functionality items.

Advantages: This is a ready-made script for issuing a forecast for the Gosloto 6 out of 45 lottery, which eliminates the need to select the required draw. Positions itself as a site that operates on special algorithms and filters that create the most likely forecasts based on the draws carried out. Allows you to get multiple results at once and share a link to the result.

Flaws: There is no possibility to enter a range of numbers and necessary exceptions. However, the biggest disadvantage is the provision of paid forecasts, which clearly sets it apart from its previous free counterparts.

Conclusion

Whether you use the services discussed or not, of course, is up to you. On the one hand, the use of such sites can help you select certain combinations, freeing you from difficult choices, since, for example, for a 5 out of 36 draw, absolutely any combination generated or manually selected by the player himself has a probability of winning of 1 in 376,992.

Table showing the probability of winning the lottery:


Compared to other lottery strategies, this option has good chances of winning. However, you should understand that using paid forecasts in this case is not advisable and does not correspond to the probability of winning.

Did you like the article? Share with your friends!