Random selection of numbers. Random number generator online

Numbers accompany us everywhere - house and apartment numbers, telephone numbers, car numbers, passport numbers, plastic card, dates, passwords Email. We choose some combinations of numbers ourselves, but most we get by chance. Without realizing it, we use randomly generated numbers every day. If we come up with pin codes, then unique codes credit or salary cards are generated by reliable systems that exclude access to passwords. Generators random numbers provide protection in areas requiring speed of information processing, security and independent processing of data.

The process of generating pseudorandom numbers is subject to certain laws and has been used for a long time, for example, in lotteries. In the recent past, drawings were carried out using lottery machines or lots. Now in many countries, the winning numbers of state lotteries are determined precisely by a set of generated random numbers.

Advantages of the method

So, a random number generator is an independent modern mechanism for randomly determining combinations of numbers. The uniqueness and perfection of this method lies in the impossibility of external intervention in the process. The generator is a set of programs built, for example, on noise diodes. The device generates a stream of random noise, the current values ​​of which are converted into numbers and form combinations.

Generating numbers provides instant results - it takes a few seconds to create a combination. If we talk about lotteries, participants can immediately find out whether the ticket number matches the winning one. This allows drawings to be held as often as participants want. But the main advantage of the method is its unpredictability and the impossibility of calculating the algorithm for selecting numbers.

How pseudorandom numbers are generated

In fact, random numbers are not random - the series starts from a given number and is generated by an algorithm. A pseudorandom number generator (PRNG or PRNG - pseudorandom number generator) is an algorithm that generates a sequence of seemingly unrelated numbers, usually subject to a uniform distribution. In computer science, pseudorandom numbers are used in many applications: cryptography, simulation modeling, Monte Carlo method, etc. The quality of the result depends on the properties of the PRNG.

The source of generation can be physical noise from cosmic radiation to noise in a resistor, but such devices have applications network security almost never used. Cryptographic applications use special algorithms that generate sequences that cannot be statistically random. However, a properly chosen algorithm can produce series of numbers that pass most randomness tests. The repetition period in such sequences is greater than the working interval from which the numbers are taken.

In many modern processors contains PRNG, for example, in RdRand. As an alternative, sets of random numbers are created and published in a one-time pad (dictionary). The source of numbers in this case is limited and does not provide complete network security.

History of PRNG

A prototype of a random number generator can be considered board game Senet, common in Ancient Egypt in 3500 BC. According to the conditions, two players participated, the moves were determined by throwing four flat black and white sticks - they were a kind of PRNG of that time. The sticks were thrown at the same time, and points were counted: if one fell up with the white side, 1 point and an additional move, two white ones - two points, and so on. The maximum result of five points was received by the player who threw four sticks with the black side.

Nowadays, the ERNIE generator has been used for many years in the UK for lottery draws. There are two main methods for generating winning numbers: linear congruent and additive congruent. These and other methods are based on the principle of random selection and are provided by software that endlessly produces numbers, the sequence of which is impossible to guess.

The PRNG operates continuously, for example, in slot machines. According to US law, this required condition, which all software providers must comply with.

Various lotteries, drawings, etc. are often held in many groups or publics in in social networks, Instagram, etc., and is used by account owners to attract new audiences to the community.

The result of such drawings often depends on the user's luck, since the recipient of the prize is determined randomly.

To make this determination, lottery organizers almost always use an online or pre-installed random number generator that is distributed free of charge.

Choice

Quite often, choosing such a generator can be difficult, since their functionality is quite different - for some it is significantly limited, for others it is quite wide.

Enough is being implemented a large number of such services, but the difficulty is that they differ in scope.

Many, for example, are tied by their functionality to a specific social network (for example, many generator applications on VKontakte work only with links from this social network).

Most simple generators they simply randomly determine a number within a given range.

This is convenient because it does not associate the result with a specific post, which means it can be used for sweepstakes outside the social network and in various other situations.

They essentially have no other use.

<Рис. 1 Генератор>

Advice! When choosing the most suitable generator, it is important to consider what it will be used for.

Specifications

For the fastest process of choosing the optimal online random number generation service, the table below shows the main specifications and functionality of such applications.

Table 1. Features of operation online applications to generate a random number
Name Social network Multiple results Select from a list of numbers Online widget for the site Select from a range Disabling repetitions
RandStuff Yes Yes No Yes No
Cast Lots Official website or VKontakte No No Yes Yes Yes
Random number Official site No No No Yes Yes
Randomus Official site Yes No No Yes No
Random numbers Official site Yes No No No No

All applications discussed in the table are described in more detail below.

<Рис. 2 Случайные числа>

RandStuff

<Рис. 3 RandStuff>

You can use this application online by following the link to its official website http://randstuff.ru/number/.

This is a simple random number generator, characterized by fast and stable operation.

It is successfully implemented both in a separate format standalone application on the official website and as an application on the social network VKontakte.

The peculiarity of this service is that it can select a random number both from a specified range and from a specific list of numbers that can be specified on the site.

Pros:

  • Stable and fast work;
  • Lack of direct connection to a social network;
  • You can select one or several numbers;
  • You can only choose among the specified numbers.

Minuses:

  • Inability to hold a drawing on VKontakte (this requires separate application);
  • Applications for VKontakte do not run in all browsers;
  • The result sometimes seems predictable because only one calculation algorithm is used.

User reviews about this application are as follows: “We determine through this service the winners in VKontakte groups. Thank you,” “You are the best,” “I only use this service.”

Cast Lots

<Рис. 4 Cast Lots>

This application is a simple function generator, implemented on the official website in the form of a VKontakte application.

There is also a generator widget for inserting into your website.

The main difference from the previous described application is that this allows you to disable the repetition of the result.

That is, when carrying out several generations in a row in one session, the number will not be repeated.

  • Availability of a widget for inserting into a website or blog;
  • Ability to disable result repetition;
  • The presence of the “even more randomness” function, after activation of which the selection algorithm changes.

Negative:

  • Inability to determine several results at once;
  • Inability to select from a specific list of numbers;
  • To select a winner in publics, you must use a separate VKontakte widget.

User reviews are as follows: “It works stably, it’s quite convenient to use”, “Convenient functionality”, “I only use this service”.

Random number

<Рис. 5 Случайное число>

This service is located at http://randomnumber.rf/.

Simple generator with minimum functions and additional features.

Can randomly generate numbers within a specified range (maximum from 1 to 99999).

The site does not have any graphic design, and therefore the page loads easily.

The result can be copied or downloaded with the click of a button.

Negative:

  • Lack of a widget for VKontakte;
  • There is no possibility of holding draws;
  • There is no way to embed the result into a blog or website.

Here's what users are saying about this service: “Not a bad generator, but not enough functions”, “Very few features”, “Suitable for quickly generating numbers without unnecessary settings.”

Randomus

<Рис. 6 Рандомус>

You can use this random number generator at http://randomus.ru/.

Another one, quite simple, but functional random number generator.

The service has sufficient functionality for determining random numbers, but it is not suitable for conducting draws and other more complex processes.

Negative:

  • Impossibility of holding drawings based on reposts of a post, etc.
  • There is no application for VKontakte or a widget for the site;
  • It is not possible to disable repeating results.

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 uniformly distributed random 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. Fractional part the formula is discarded.

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.

From the list text values you need to choose 2 random ones. 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 single 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 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 can generate a diagram with a normal distribution. The value axis is the number of variables in the interval, the category axis is periods.

Submitted by online generator random numbers works based on a pseudo-random number generator with a uniform distribution built into JavaScript. Integers are generated. By default, 10 random numbers are output in the range 100...999, the numbers separated by spaces.

Basic settings of the random number generator:

  • Amount of numbers
  • Number range
  • Separator type
  • Turn on/off the function of removing repetitions (duplicates of numbers)

The total number is formally limited to 1000, with a maximum of 1 billion. Delimiter options: space, comma, semicolon.

Now you know exactly where and how to get a free sequence of random numbers in a given range on the Internet.

Application options for a random number generator

A random number generator (RNG in JS with uniform distribution) will be useful for SMM specialists and owners of groups and communities on the social networks Instagram, Facebook, VKontakte, Odnoklassniki to determine the winners of lotteries, competitions and prize draws.

A random number generator allows you to draw prizes among an arbitrary number of participants with a specified number of winners. Contests can be held without reposts and comments - you yourself set the number of participants and the interval for generating random numbers. You can get a set of random numbers online and for free on this site, and you do not need to install any application on your smartphone or program on your computer.

Also, an online random number generator can be used to simulate tossing a coin or dice. However, we have separate specialized services for these cases.

  • 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 next sequence, which means that such an algorithm is not suitable, 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 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 work complex generators random numbers.

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:<30; i++) console.log(rand())
Const a = 45; const c = 21; const m = 67; var seed = 2; const rand = () => seed = (a * seed + c) % m; for(let i=0; i

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
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...).