Random number formula. Excel Random Number Generator in Functions and Data Analysis

Good day, dear reader!

Recently, the need arose to create a kind of generator random numbers in Excel within borders required task, but it was simple, taking into account the number of people, choosing a random user, everything is very simple and even banal. But I was interested in what else can be done with the help of such a generator, what they are, what their functions are used for this and in what form. There are a lot of questions, so I will gradually answer them.

So, what exactly can we use this mechanism for:

  • Firstly: to test formulas, we can fill the range we need with random numbers;
  • secondly: to generate questions for various tests;
  • thirdly: for any random distribution of tasks in advance among your employees;
  • fourthly: for simulation a wide variety of processes;

……and in many other situations!

In this article I will consider only 3 options for creating a generator (I will not describe macro capabilities), namely:

Creating a random number generator using the RAND function

Using the RAND function, we have the ability to generate any random number in the range from 0 to 1 and this function will look like this:

=RAND();

If the need arises, and it most likely will, use a random number of great importance, you can simply multiply your function by any number, for example 100, and you will get:

=RAND()*100;
But if you don't like fractional numbers or just need to use integers, then use this combination of functions, it will allow you to follow the comma or just discard them:

=ROUND((RAND()*100);0);

=RESULT((RAND()*100);0)
When there is a need to use a random number generator in a certain, specific range, according to our conditions, for example, from 1 to 6, you need to use the following construction (be sure to secure the cells with ):

=RAND()*(b-a)+a, Where,

And complete formula will look like: =RAND()*(6-1)+1, and without fractional parts you need to write: =RESULT(RAND()*(6-1)+1;0)

Create a random number generator using the RANDBETWEEN function

This function is simpler and began to please us in the basic version of Excel, after the 2007 version, which greatly simplified the work with the generator when it is necessary to use a range. For example, to generate a random number in the range from 20 to 50, we will use the following construction:

=RANDBETWEEN(20,50).

Create a generator using the AnalysisToolPack add-on

The third method does not use any generation function, but everything is done using an add-on AnalysisToolPack(This add-in is included with Excel.) The tool built into the table editor can be used as a generation tool, but you need to know that if you want to change the set of random numbers, then you need to restart this procedure.

To gain access to this undeniably useful add-on, you first need to use the dialog box "Add-ons" install this package. If you already have it installed, then the matter is small, select the menu item “Data” – “Analysis” – “Data Analysis”, select from the list offered by the program and click "OK".

In the window that opens, we select the type from the menu "Distribution", then we indicate additional parameters that change based on the type of distribution. Well, the final step is this indication "Output Interval", exactly the interval where your random numbers will be stored.

And that's all for me! I really hope that I fully explained the question of creating a random number generator and everything is clear to you. I would be very grateful for your comments, as this is an indicator of readability and inspires me to write new articles! Share what you read with your friends and like it!

Don't think too much. This is how you create problems that weren’t there in the first place.

Friedrich Nietzsche

Function RAND() returns a uniformly distributed random number x, where 0 £ x< 1. Вместе с тем путем несложных преобразований с помощью функции RAND() you can get any random real number. For example, to get a random number between a And b, just set in any cell Excel tables the following formula: =RAND()*( b-a)+a .

Note that starting with Excel 2003, the function RAND() has been improved. It now implements the Wichman-Hill algorithm, which passes all standard tests for randomness and guarantees that repetition in a combination of random numbers will begin no earlier than after 10 13 generated numbers.

Random number generator in STATISTICA

To generate random numbers in STATISTICA, you need to double-click on the variable name in the data table (in which you are supposed to write the generated numbers). In the variable specification window, click the button Functions. In the window that opens (Fig. 1.17), you need to select Math and select a function Rnd .

RND(X ) - generation of uniformly distributed numbers. This function has only one parameter - X , which specifies the right boundary of the interval containing random numbers. In this case, 0 is the left border. To enter general view functions RND (X ) into the variable specification window, just double-click on the function name in the window Function Browser . After specifying numerical value parameter X need to press OK . The program will display a message indicating that the function was written correctly and will ask for confirmation about recalculating the value of the variable. After confirmation, the corresponding column is filled with random numbers.

Assignment for independent work

1. Generate series of 10, 25, 50, 100 random numbers.

2. Calculate descriptive statistics



3. Construct histograms.

What conclusions can be drawn regarding the type of distribution? Will it be uniform? How does the number of observations affect this conclusion?

Lesson 2

Probability. Simulation of a complete group of events

Laboratory work No. 1

Laboratory work is independent research followed by protection.

Lesson objectives

Formation of stochastic modeling skills.

Understanding the essence and connection of the concepts “probability”, “relative frequency”, “statistical definition of probability”.

Experimental verification of the properties of probability and the possibility of calculating probability random event empirically.

- Formation of skills for studying phenomena of a probabilistic nature.

The events (phenomena) we observe can be divided into the following three types: reliable, impossible and random.

Reliable name an event that is sure to occur if a certain set of conditions is met S.

Impossible an event that is known to not occur if a set of conditions is met S.

Random call an event that, when a set of conditions S is fulfilled, can either occur or not occur.

The subject of probability theory is the study of probabilistic patterns of mass homogeneous random events.

Events are called incompatible, if the occurrence of one of them excludes the occurrence of other events in the same trial.

Several events form full group, if at least one of them appears as a result of the test. In other words, the occurrence of at least one of the events of the complete group is a reliable event.

Events are called equally possible, if there is reason to believe that none of these events is more possible than the others.

Each of the equally possible test results is called elementary outcome.

Classic definition of probability: probability of an event A call the ratio of the number of outcomes favorable to this event to the total number of all equally possible incompatible elementary outcomes, forming a complete group.

A is determined by the formula,

Where m– the number of elementary outcomes favorable to the event A, n– the number of all possible elementary test outcomes.

One of the disadvantages of the classical definition of probability is that it does not apply to trials with an infinite number of outcomes.

Geometric definition probability generalizes the classical one to the case infinite number elementary outcomes and represents the probability of a point falling into a region (segment, part of a plane, etc.).

Thus, the probability of an event A is defined by the formula , where is the measure of the set A(length, area, volume); – measure of the space of elementary events.

Relative frequency, along with probability, belongs to the basic concepts of probability theory.

Relative frequency of the event is the ratio of the number of trials in which the event occurred to the total number of trials actually performed.

Thus, the relative frequency of the event A is determined by the formula where m– number of occurrences of the event, ntotal number tests.

Another disadvantage of the classical definition of probability is that it is difficult to indicate the reasons for considering elementary events equally possible. For this reason, along with classical definition also enjoy statistical definition probabilities, taking the relative frequency or a number close to it as the probability of an event.

1. Simulation of a random event with probability p.

A random number is generated y yp, then event A has occurred.

2. Simulation of a complete group of events.

Let us number the events that form a complete group with numbers from 1 to n(Where n– number of events) and draw up a table: in the first line – the event number, in the second – the probability of the occurrence of an event with the specified number.

Event number j n
Probability of event

Let's divide the segment into axis Oy points with coordinates p 1 , p 1 +p 2 , p 1 +p 2 +p 3 ,…, p 1 +p 2 +…+p n-1 on n partial intervals Δ 1 , Δ 2 ,…, Δ n. In this case, the length partial interval with number j equal to probability p j.

A random number is generated y, uniformly distributed on the segment. If y belongs to the interval Δ j, then event A j it has arrived.

Laboratory work No. 1. Experimental calculation of probability.

Objectives: modeling random events, studying properties statistical probability events depending on the number of trials.

Laboratory work We will do it in two stages.

Stage 1. Simulation of a symmetrical coin toss.

Event A consists in the loss of the coat of arms. Probability p events A equal to 0.5.

a) It is necessary to find out what the number of tests should be n so that with a probability of 0.9 deviation (according to absolute value) relative frequency appearance of the coat of arms m/n from probability p = 0.5 did not exceed the number ε > 0: .

Carry out calculations for ε = 0.05 and ε = 0.01. For calculations we use the corollary from integral theorem Moivre-Laplace:

Where ; q=1-p.

How are the values ​​related? ε And n?

b) Conduct k= 10 episodes n tests in each. In how many series is the inequality satisfied and in how many is it violated? What will be the result if k→ ∞?

Stage 2. Modeling the implementation of the outcomes of a random experiment.

a) Develop an algorithm for modeling the implementation of an experiment with random outcomes according to individual assignments(see appendix 1).

b) Develop a program (programs) to simulate the implementation of the outcomes of a certain experiment final number times, with mandatory saving initial conditions experience and to calculate the frequency of occurrence of the event of interest.

c) Compile a statistical table of the dependence of the frequency of occurrence of a given event on the number of experiments performed.

d) Using the statistical table, construct a graph of the frequency of an event depending on the number of experiments.

e) Compile a statistical table of deviations of the frequency values ​​of an event from the probability of occurrence of this event.

f) Reflect the obtained tabular data on graphs.

g) Find the value n(number of trials) so that and .

Draw conclusions from the work.

Random numbers are often useful in spreadsheets. For example, you can fill a range with random numbers to test formulas, or generate random numbers to simulate a wide variety of processes. Excel provides several ways to generate random numbers.

Using the RAND function

Featured in Excel function RAND generates a uniform random number between 0 and 1. In other words, any number between 0 and 1 has equal probability be returned by this function. If you need random numbers with large values, use simple formula multiplication. The following formula, for example, generates a uniform random number between 0 and 1000:
=RAND()*1000 .

To restrict the random number to integers, use the function ROUND:
=ROUND((RAND()*1000);0) .

Using the RANDBETWEEN function

To generate uniform random numbers between any two numbers you can use the function CASE BETWEEN. The following formula, for example, generates a random number between 100 and 200:
=RANDBETWEEN(100,200) .

In versions earlier than Excel 2007, the function CASE BETWEEN Available only when installing an additional analysis package. For backward compatibility (and to avoid using this add-on), use a formula like this: A represents the bottom, a b- upper limit: =RAND()*(b-a)+a. To generate a random number between 40 and 50, use the following formula: =RAND()*(50-40)+40 .

Using the Analysis ToolPack Add-in

Another way to get random numbers in a worksheet is to use the plugin Analysis ToolPack(which came with Excel). This tool can generate uneven random numbers. They are not generated by formulas, so if you need a new set of random numbers, you need to rerun the procedure.

Get access to the package Analysis ToolPack by selecting Data Analysis Data Analysis. If this command is missing, install the package Analysis ToolPack using the dialog box Add-ons. The easiest way to call it is to press Atl+TI. In the dialog box Data Analysis select Random number generation and press OK. A window will appear as shown in Fig. 130.1.

Select the distribution type from the drop-down list Distribution, and then set additional parameters (these vary depending on the distribution). Don't forget to specify the parameter Output interval, which stores random numbers.

Excel has a function for finding random numbers =RAND(). The ability to find a random number in Excel is an important component of planning or analysis, because you can predict the results of your model on a large amount of data, or just find one random number to test your formula or experience.

Most often this function is used to obtain large quantity random numbers. Those. You can always come up with 2-3 numbers yourself; for a large number it’s easiest to use a function. In most programming languages, a similar function is known as Random (from English random), so you can often come across the Russified expression “in random order”, etc. In English Excel, the RAND function is listed as RAND

Let's start with a description of the function =RAND(). This function requires no arguments.

And it works as follows: it outputs a random number from 0 to 1. The number will be real, i.e. By by and large any, usually this decimals, for example 0.0006.

Each time you save the number will change; to update the number without updating, press F9.

A random number within a certain range. Function

What to do if the existing range of random numbers does not suit you, and you need a set of random numbers from 20 to 135. How can this be done?

You need to write down the following formula.

RAND()*115+20

Those. a number from 0 to 115 will be randomly added to 20, which will allow you to get a number in the desired range each time (see the first picture).

By the way, if you need to find an integer in the same range, there is a special function for this, where we indicate the upper and lower bounds of the values

RANDBETWEEN(20,135)

Simple, but very convenient!

If you need multiple random number cells just drag the cell below.

Random number with a certain step

If we need to get a random number in increments, for example five, then we will use one of. This will be OKRUP()

AROUNDTOP(RAND()*50,5)

Where we find a random number from 0 to 50 and then round it up to the nearest multiple of 5. Handy when you're doing the calculation for sets of 5.

How to use random to test a model?

You can check the invented model using a large number of random numbers. For example, check whether a business plan will be profitable

It was decided to include this topic in a separate article. Stay tuned for updates this week.

Random number in VBA

If you need to record a macro and you don’t know how to do it, you can read.

VBA uses the function Rnd(), but it will not work without enabling the command Randomize to run the random number generator. Let's calculate a random number from 20 to 135 using a macro.

Sub MacroRand() Randomize Range("A24") = Rnd * 115 + 20 End Sub

Paste this code into VBA editor (Alt + F11)

As always, I apply example* with all payment options.

Write comments if you have questions!

Share our article on your social networks:

We have a sequence of numbers consisting of almost independent elements who obey 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 limit). 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 choose one random value from the list, apply 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 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 plot a graph with a normal distribution at standard deviation 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.



Did you like the article? Share with your friends!