How many candies should you buy to get all the toys?

In summary, the conversation revolves around different ways to solve the problem of determining the probability of getting all numbers from a set when randomly selecting a certain amount of numbers from that set. The conversation also touches upon the coupon collector's problem and the use of mathematical formulas to solve such problems. Some participants prefer simpler calculations while others prefer more precise ones.
  • #1
jostpuur
2,116
19
Suppose we have a random number generator which gives a random numbers from a set {1,2,3,...,N}, and any single number of these comes out with probability 1/N.

Then fix some number M > N, and take M random numbers out from the generator. What is the probability, that these M numbers include each one of the numbers 1,2,3,...,N at least once?

---

I know one person who buys some kind of candy where a small toy always comes with the candy. There is some number of different kind of toys out there, and this person became interested to know how many candy he/she should buy before getting them all. I found myself unable to answer it.
 
Mathematics news on Phys.org
  • #2
jostpuur said:
I know one person who buys some kind of candy where a small toy always comes with the candy. There is some number of different kind of toys out there, and this person became interested to know how many candy he/she should buy before getting them all. I found myself unable to answer it.

You would need to know the distribution of the toys. Are there more toy cars than toy boats? Obviously, if it's not uniform, you would have to buy a lot more to get one of each.
 
  • #3
I told the background about toys and candy for sake of motivation, but in the end I'm interested in the mathematical problem which I outlined.

If a simple mathematical model for a real world problem is too difficult, then it doesn't make sense to seek for more complicated models either. It's better to solve models one step at a time.
 
  • #4
Well, I can model how many numbers I would have to draw from a set of 10 to get at least 1 of each (a mean of 29.5).
 
  • #5
Mensanator said:
Well, I can model how many numbers I would have to draw from a set of 10 to get at least 1 of each (a mean of 29.5).

How did you get this number 29.5?
 
  • #6
Your first question is easy to turn into balls and boxes:

We have M balls and N boxes, with M > N. We want to know
  • How many ways are there to put the balls into the boxes
  • How many ways are there to put the balls into the boxes such that each box has at least one ball

I claim the first one is easy. I think the second one can be transformed into an easy problem, but I'm having a mental block on the details.




Your second question is a famous problem -- the coupon collector's problem.
 
Last edited:
  • #7
I see. So the collector's problem can be solved without solving the problem I described, although my problem would give one way of approaching the collector's problem.
 
  • #8
jostpuur said:
How did you get this number 29.5?

By randomly selecting numbers in the range (0-9) and storing them in a dictionary. When the length of the dictionary reaches 10, there must be a least 1 of every value. At that point, the sum of the dictionary is the number of draws. On some runs, it might take only 17 draws to get all 10, other runs might take 45. I do 1000 such runs and take the average: 29.5.
 
  • #9
Hurkyl said:
Your first question is easy to turn into balls and boxes:

We have M balls and N boxes, with M > N. We want to know
  • How many ways are there to put the balls into the boxes
  • How many ways are there to put the balls into the boxes such that each box has at least one ball

I claim the first one is easy. I think the second one can be transformed into an easy problem, but I'm having a mental block on the details.




Your second question is a famous problem -- the coupon collector's problem.

The first one is simply M choose N.

The second one is simply (M-1) choose (N-1).

(This turns up in the Collatz Conjecture.)
 
  • #10
Mensanator said:
By randomly selecting numbers in the range (0-9) and storing them in a dictionary. When the length of the dictionary reaches 10, there must be a least 1 of every value. At that point, the sum of the dictionary is the number of draws. On some runs, it might take only 17 draws to get all 10, other runs might take 45. I do 1000 such runs and take the average: 29.5.

After reading Hurkyl's link to the Wikipedia page, I would prefer a following calculation

[tex]
10\cdot\Big(1 + \frac{1}{2} + \frac{1}{3} + \cdots + \frac{1}{10}\Big) \approx 29.29
[/tex]

:wink:
 
  • #11
jostpuur said:
After reading Hurkyl's link to the Wikipedia page, I would prefer a following calculation

[tex]
10\cdot\Big(1 + \frac{1}{2} + \frac{1}{3} + \cdots + \frac{1}{10}\Big) \approx 29.29
[/tex]

:wink:

You DO realize you can't get a fraction of a draw from a random number generator?
 
  • #12
Mensanator said:
You DO realize you can't get a fraction of a draw from a random number generator?

Why would that preclude a fractional answer?
 
  • #13
CRGreathouse said:
Why would that preclude a fractional answer?

I didn't say it would. But IF I don't have the formula at hand AND Wikipedia is not available, THEN I prefer my answer as there's nothing stopping me from obtaining it and it's good enough. The difference between 29.29 and 29.5 is just splitting hairs.
 
  • #14
I would not see it as exactly splitting hairs.

Euler has a formula for the harmonic series http://en.wikipedia.org/wiki/Harmonic_number:

[tex] In(n) +\gamma +1/2n -1/(12n^2)+ 1/(12n^4)- +-[/tex]

Letting gamma be .5772 and dropping terms past the square factor gives about 29.29 after multiplication by 10.

It is rather useful to get a handle on the degree of error. I prefer such a calculation to a computer devised answer that does not tell us about the error involved.
 
Last edited by a moderator:
  • #15
robert Ihnot said:
I would not see it as exactly splitting hairs.

Euler has a formula for the harmonic series http://en.wikipedia.org/wiki/Harmonic_number:

[tex] In(n) +\gamma +1/2n -1/(12n^2)+ 1/(12n^4)- +-[/tex]

Letting gamma be .5772 and dropping terms past the square factor gives about 29.29 after multiplication by 10.

It is rather useful to get a handle on the degree of error. I prefer such a calculation to a computer devised answer that does not tell us about the error involved.

Like I said, that's fine IF you know Euler's formula. A computer devised answer is preferable to no answer.
 
Last edited by a moderator:
  • #16
My gosh! I must add that my TI-86 can sum up the 50 case IN FOUR SECONDS! giving 224.96.

As far as this 10 case, why plain arithmetic will do here: 1+.5+.3333+.2500 + .2000+.1667+.1429+.1250 +.1111+.1000 = 2.9290.

2.929x10 = 29.290. This can be summed in about 30 seconds. If very careful probably around 45 seconds.
 

1. What is the purpose of generating M random numbers from 1 to N?

The purpose of generating M random numbers from 1 to N is to create a set of numbers that are independent and uniformly distributed within the range of 1 to N. This can be useful in various applications, such as statistical analysis, simulation, and cryptography.

2. How are random numbers generated?

Random numbers can be generated using various techniques, such as using a physical source of randomness (like rolling dice or flipping coins), using mathematical algorithms, or using computer software. Each method has its own advantages and limitations, and the choice of method depends on the specific application.

3. What is the difference between pseudo-random and truly random numbers?

Pseudo-random numbers are generated using a deterministic algorithm, which means that the same sequence of numbers will be produced each time the algorithm is run with the same starting point or "seed". Truly random numbers, on the other hand, are generated using a physical source of randomness and are not predictable. Pseudo-random numbers are often used in simulations and computer software, while truly random numbers are used in cryptography and other applications where unpredictability is essential.

4. How can we test the randomness of generated numbers?

There are various statistical tests that can be performed to evaluate the randomness of generated numbers. These tests measure properties such as distribution, autocorrelation, and independence. Some commonly used tests include the chi-square test, Kolmogorov-Smirnov test, and runs test. However, it should be noted that no test can definitively prove the randomness of a sequence of numbers, as there is always a possibility of a pattern occurring by chance.

5. Can we generate random numbers with specific characteristics?

Yes, it is possible to generate random numbers with specific characteristics by using specialized algorithms. For example, if we want to generate random numbers that follow a normal distribution, we can use the Box-Muller transform. Similarly, for creating random numbers with a specific correlation or other properties, there are algorithms available. However, it should be noted that these numbers are still considered pseudo-random, as they are generated using deterministic methods.

Similar threads

Replies
4
Views
379
Replies
7
Views
1K
Replies
6
Views
1K
  • General Math
Replies
4
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
7
Views
303
Replies
1
Views
3K
  • Science Fiction and Fantasy Media
Replies
0
Views
954
  • General Math
Replies
2
Views
1K
  • General Math
Replies
1
Views
1K
Back
Top