# Several probabilities questions

**URL:** <https://boards.straightdope.com/t/several-probabilities-questions/642208>\
**Category:** Factual Questions\
**Created:** [November 26, 2012, 10:43pm UTC](https://boards.straightdope.com/t/several-probabilities-questions/642208 "2012-11-26T22:43:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Enderw24](https://avatars.discourse-cdn.com/v4/letter/e/ba9def/32.png) [@Enderw24](https://boards.straightdope.com/u/Enderw24)\
**Post date:** [November 26, 2012, 10:43pm UTC](https://boards.straightdope.com/t/several-probabilities-questions/642208/1 "2012-11-26T22:43:00Z")

</div>

I’m playing around with [Random.Org](http://Random.Org) and a few questions popped into my head.  
I created a random list of 10,000 numbers from a list from 1-10,000. Since there were repeats, it was obvious that the random number generator didn’t eliminate numbers once they were used.

I plug the list of numbers into an Excel spreadsheet column and put them in numerical order. Then I compare that list of numbers to their row numbers and note the difference between them.

For instance, if the numbers 1-8 were chosen at random for 1,5,8,2,6,4,5,4.  
In numerical order they’d be  
1  
2  
4  
4  
5  
5  
6  
8

And you’d note that #1, 2, 4, 5, and 8 were the 1st, 2nd, 4th, 5th and 8th numbers.

I did this twice. Once 202/10,000 matched. The second time 141/10,000 numbers matched.

First question is what’s the expected number of matches in a list of 10,000? How would you even go about figuring that out?

Second, I also looked at how far off the number was from the row number. I subtracted the row# from the actual# and came up with one range of -99 through 34 and another with a range of -91 through 27.  
What would the expected range be over the long term of doing this experiment?

---

<div class="post-metadata">

**Author:** ![OldGuy](https://avatars.discourse-cdn.com/v4/letter/o/3bc359/32.png) [@OldGuy](https://boards.straightdope.com/u/OldGuy)\
**Post date:** [November 26, 2012, 11:55pm UTC](https://boards.straightdope.com/t/several-probabilities-questions/642208/2 "2012-11-26T23:55:11Z")

</div>

I can’t answer your question off the top of my head, but what you’re looking for for the first question is “order statistics.”

---

<div class="post-metadata">

**Author:** ![Chronos](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/chronos/32/134_2.png) [@Chronos](https://boards.straightdope.com/u/Chronos)\
**Post date:** [November 27, 2012, 1:42am UTC](https://boards.straightdope.com/t/several-probabilities-questions/642208/3 "2012-11-27T01:42:36Z")

</div>

I don’t have the math handy to back me up, but I would expect both to scale as the square root of the sample size. Thus, for instance, if you picked a million numbers up to a million, you’d have a thousand-ish of them in the right place, and the ones that were out of place could be out by as much as a thousand-ish places.

---

<div class="post-metadata">

**Author:** ![CookingWithGas](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/cookingwithgas/32/485_2.png) [@CookingWithGas](https://boards.straightdope.com/u/CookingWithGas)\
**Post date:** [November 27, 2012, 3:00am UTC](https://boards.straightdope.com/t/several-probabilities-questions/642208/4 "2012-11-27T03:00:58Z")

</div>

I don’t know the answer to the questions but

> [@Enderw24](#):
>
> Since there were repeats, it was obvious that the random number generator didn’t eliminate numbers once they were used.

it wouldn’t be a random number generator if it did.

---

<div class="post-metadata">

**Author:** ![Lance\_Turbo](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lance_turbo/32/6156_2.png) [@Lance\_Turbo](https://boards.straightdope.com/u/Lance_Turbo)\
**Post date:** [November 27, 2012, 4:02am UTC](https://boards.straightdope.com/t/several-probabilities-questions/642208/5 "2012-11-27T04:02:04Z")

</div>

The general solution “expected number of matches” when drawing n number from 1…n with replacement is:

Sum for 0 \<= k \<= n-1 (n!/(k! n^(n-k)))

When n = 10,000 Python tells me the expectation is 124.99912186808118.

---

<div class="post-metadata">

**Author:** ![Enderw24](https://avatars.discourse-cdn.com/v4/letter/e/ba9def/32.png) [@Enderw24](https://boards.straightdope.com/u/Enderw24)\
**Post date:** [November 27, 2012, 4:52am UTC](https://boards.straightdope.com/t/several-probabilities-questions/642208/6 "2012-11-27T04:52:36Z")

</div>

> [@Chronos](#):
>
> I don’t have the math handy to back me up, but I would expect both to scale as the square root of the sample size. Thus, for instance, if you picked a million numbers up to a million, you’d have a thousand-ish of them in the right place, and the ones that were out of place could be out by as much as a thousand-ish places.

Interesting. So you’d believe that the number of matches should roughly equal the total range away from 0? My ranges were around 120-130 for both. Both heavily skewed in one direction, though I imagine that was just a quirk of two samples and it would even itself out over time.

> [@Lance\_Turbo](#):
>
> The general solution “expected number of matches” when drawing n number from 1..n with replacement is:
> 
> Sum for 0 \<= k \<= n-1 (n!/(k! n^(n-k)))
> 
> When n = 10,000 Python tells me the expectation is 124.99912186808118.

Sorry, what’s k?

---

<div class="post-metadata">

**Author:** ![ultrafilter](https://avatars.discourse-cdn.com/v4/letter/u/3d9bf3/32.png) [@ultrafilter](https://boards.straightdope.com/u/ultrafilter)\
**Post date:** [November 27, 2012, 5:00am UTC](https://boards.straightdope.com/t/several-probabilities-questions/642208/7 "2012-11-27T05:00:48Z")

</div>

k is the index of summation.

---

<div class="post-metadata">

**Author:** ![Buck\_Godot](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/buck_godot/32/6573_2.png) [@Buck\_Godot](https://boards.straightdope.com/u/Buck_Godot)\
**Post date:** [November 27, 2012, 6:28pm UTC](https://boards.straightdope.com/t/several-probabilities-questions/642208/8 "2012-11-27T18:28:27Z")

</div>

To Answer the second question, consider dividing all the number on your list by N so that all of your data lies between 0 and 1. Then looking at the largest deviation is exactly the same a performing a[Kolmogorov–Smirnov test](http://en.wikipedia.org/wiki/Kolmogorov%E2%80%93Smirnov_statistichttp://). for repeated runs the number of negative or positive ranges should be symmetric, but within a run of 10,000 there may by chance be a tendency one way or another.

Overall you expect a maximal absolute difference of about 0.83_Sqrt(N) with 95% or repeated runs falling between 0.48_Sqrt(N) and 1.48\*Sqrt(N)
