How to get Excel to generate any random number besides x?

In summary, my solution is to use a scheme in which the output of the random number generator is used to select a seat. For example, if there are three seats available, the lowest numbered ticket gets to choose one of them.
  • #1
moonman239
282
0
Here's my dillemma:

I'm writing up a spreadsheet where we have 100 passengers on a plane. Excel randomly generates their assigned seat, and the seat they end up taking. But the problem is, I need to make it so that Excel does not generate the same number twice.
 
Physics news on Phys.org
  • #2
moonman239 said:
Here's my dillemma:

I'm writing up a spreadsheet where we have 100 passengers on a plane. Excel randomly generates their assigned seat, and the seat they end up taking. But the problem is, I need to make it so that Excel does not generate the same number twice.
The problem is that you're not asking the right question. :smile:


You seem to be trying to make the random number generator output seat assignments, and running into the problem that it can output the same number twice.


But what you should be trying to do is to find a (fair) scheme for using the output of the random number generator to select a seat.
 
  • #3
Hurkyl said:
You seem to be trying to make the random number generator output seat assignments, and running into the problem that it can output the same number twice.

But what you should be trying to do is to find a (fair) scheme for using the output of the random number generator to select a seat.

Any suggestions?
 
  • #4
Generate 100 random real numbers between 0 and 1. It is unlikely you will get two numbers exactly the same, but it doesn't matter if that happens.
Label the numbers "1" to "100".
Sort them.
Use the sorted order of the labels as your seat assignments

For example using 3 seat numbers, suppose your random numbers were
0.4, 0.7, 0.2
Label them in the order they were generated:
1: 0.4
2: 0.7
3: 0.2
Sort them:
3: 0.2
1: 0.4
2: 0.7
Your random seat assigments are 3, 1, 2
 
  • #5
AlephZero said:
Generate 100 random real numbers between 0 and 1. It is unlikely you will get two numbers exactly the same, but it doesn't matter if that happens.
Label the numbers "1" to "100".
Sort them.
Use the sorted order of the labels as your seat assignments

For example using 3 seat numbers, suppose your random numbers were
0.4, 0.7, 0.2
Label them in the order they were generated:
1: 0.4
2: 0.7
3: 0.2
Sort them:
3: 0.2
1: 0.4
2: 0.7
Your random seat assigments are 3, 1, 2

Excuse me for asking this, but could you please further explain your example?
 
  • #6
Here's my solution to the problem as I understand it.

Let's say the craft has 10 rows of seats with three seats on each row. That's a matrix with 10 rows and 3 columns. X can take on 3 values: left, middle, right. Y can take on values from 1 to 10. Let x and y be the actual random numbers generated independently. For example, if there is one person boarding, generate one x and one y independently. Suppose x = 0.523566 and y = 0.121252. Since 1/3 < x < 2/3, X = middle. Since 0.1 < y < 0.2, Y = 2 i.e. it's the second row, so the passenger requests "middle seat on the second row." Do this as many times as there are passengers. If a passenger requests a seat which is "taken," then keep generating new pairs of numbers for that person until they request one of the seats that has remained empty until then.
 
  • #7
moonman239 said:
Excuse me for asking this, but could you please further explain your example?

There are two different ways to think about your seat assignment problem.

Your OP is thinking about the same way that it happens in real life. The first passenger turns up and chooses a seat and random. Then the second passenger chooses one of the remaining empty seats at random, etc.

The other way to look at it is to see what you have after the plane has been filled up. Now, the first seat contains the passenger who was at some random position in the queue of passengers. The second seat contains the passenger who was at another (different) random position in the queue, etc.

My method uses the second way to think about it, not the first. Imagine you have all the passengers in a queue waiting to board the plane. You give them all lottery tickets with different random numbers on them.

Then you say, "the passenger with the lowest numbered ticket gets to sit in seat 1". In my example, that was the third person waiting in the queue. Then you say, "the passenger with the next lowest numbered ticket ges to sit in seat 2", etc.

The "sorting" step of my procedure is a quick way to do this all at once, rather than picking out the smallest numbers one at a time. But you could pick them one at a time if you want to.

I used real numbers instead of integers for the "lottery tickets numbers", so it is very unlikely you get two "tickets" with the same number. But if two tickets DO have the same number, all it means is that those two people sit in adjacent seat numbers, and which of them sits in which of seat doesn't affect the randomness much, because this situation will be very rare in practice.

Hope that helps.
 

1. How can I get Excel to generate a random number between a specific range?

To generate a random number between a specific range in Excel, use the formula =RANDBETWEEN(bottom, top). Replace "bottom" with the lowest number in your desired range and "top" with the highest number. For example, to generate a random number between 1 and 10, the formula would be =RANDBETWEEN(1, 10).

2. Can I generate a random decimal number in Excel?

Yes, you can generate a random decimal number in Excel using the formula =RAND(). This will generate a decimal number between 0 and 1. To generate a decimal number within a specific range, use the formula =RANDBETWEEN(bottom, top)/RAND() and replace "bottom" and "top" with your desired range.

3. How do I generate a unique random number in Excel?

To generate a unique random number in Excel, you can use the RANDARRAY function. This function allows you to specify the number of unique random numbers you want to generate and the range of numbers to choose from. For example, the formula =RANDARRAY(5,1,1,10) will generate 5 unique random numbers between 1 and 10.

4. What if I want to generate a random number based on a specific distribution?

Excel has several functions that allow you to generate random numbers based on specific distributions. For example, you can use the NORM.INV function to generate a random number from a normal distribution, or the BINOM.INV function to generate a random number from a binomial distribution. You can also use the RAND function in combination with other functions, such as LOGNORM.INV or UNIFORM, to generate random numbers based on different distributions.

5. Can I generate a random number without using a formula?

Yes, you can generate a random number in Excel without using a formula by using the Data Analysis Toolpak. This add-in allows you to generate random numbers based on different distributions, including normal, uniform, and exponential. To access the Data Analysis Toolpak, go to the Data tab, click on Data Analysis, and then select Random Number Generation.

Similar threads

  • Programming and Computer Science
Replies
1
Views
638
  • Set Theory, Logic, Probability, Statistics
Replies
15
Views
1K
  • Computing and Technology
Replies
20
Views
693
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Programming and Computer Science
Replies
22
Views
3K
Replies
1
Views
3K
  • Precalculus Mathematics Homework Help
Replies
29
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
5
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
7
Views
338
Back
Top