Probability Archives - Anuj Varma, Hands-On Technology Architect, Clean Air Activist https://www.anujvarma.com/category/physics-math/math-science-stuff/probability/ Production Grade Technical Solutions | Data Encryption and Public Cloud Expert Fri, 28 Nov 2025 01:56:09 +0000 en-US hourly 1 https://wordpress.org/?v=6.9.4 https://www.anujvarma.com/wp-content/uploads/anujtech.png Probability Archives - Anuj Varma, Hands-On Technology Architect, Clean Air Activist https://www.anujvarma.com/category/physics-math/math-science-stuff/probability/ 32 32 Running Sum of Randomly Generated Numbers https://www.anujvarma.com/running-sum-of-randomly-generated-numbers/ https://www.anujvarma.com/running-sum-of-randomly-generated-numbers/#respond Thu, 27 Nov 2025 15:17:43 +0000 http://www.anujvarma.com/?p=3152 Integers from 1 to N are randomly generated . Each integer has an equal probability of being selected and unlimited repetition is permitted. A running sum is maintained. Given any […]

The post Running Sum of Randomly Generated Numbers appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>

Integers from 1 to N are randomly generated . Each integer has an equal probability of being selected and unlimited repetition is permitted. A running sum is maintained.

Given any integer k, such that 1 <= k <= n , what is the probability that a sum of EXACTLY n will be reached?

Probabilities of Partial Sums

Let P(n,k) be the probability that a run using the integer n will produce a sum of exactly k.



 

Probability of Hitting Exactly n

Integers from 1 to k are repeatedly drawn uniformly at random (with replacement) and a running sum is maintained. We ask:
for a fixed target integer n, what is the probability that some partial sum equals exactly n?

1. Interpretation

At each step you add an independent uniform draw from the set \(\{1,2,\dots,k\}\) (each with probability \(1/k\)). If, at any time, the running sum equals \(n\) we say the target is hit. If the running sum exceeds \(n\) that trial has failed to hit exactly \(n\).

2. Recurrence (computational)

Let \(P(n)\) denote the probability that the process will reach exactly \(n\) starting from sum 0. Then

\[ P(0)=1,\qquad P(n)=\frac{1}{k}\sum_{i=1}^{k} P(n-i)\quad\text{for }n\ge1,\]
with the convention \(P(m)=0\) for \(m<0\).

This recurrence follows by conditioning on the first draw: if the first draw is \(i\) (probability \(1/k\)), we then need to reach \(n-i\) from there.

3. Generating function

Define \(G(x)=\sum_{n\ge0} P(n)x^n\). The recurrence implies

\[ G(x)=\frac{1}{1-\dfrac{x}{k}\cdot\dfrac{1-x^{k}}{1-x}}. \]

Equivalently,

\[ G(x)=\frac{1-x}{1-x-\dfrac{x}{k}(1-x^{k})}. \]

4. Combinatorial (closed-form finite sum)

Let \(a(n,m)\) be the number of ordered sequences (compositions) of length \(m\) whose parts lie in \(\{1,\dots,k\}\) and that sum to \(n\). Then

\[ P(n)=\sum_{m=\lceil n/k\rceil}^{n} a(n,m)\left(\frac{1}{k}\right)^m. \]

The integer counts \(a(n,m)\) have an inclusion–exclusion formula (bounded-compositions / stars-and-bars with upper bounds):

\[ a(n,m)=\sum_{j=0}^{\left\lfloor\dfrac{n-m}{k}\right\rfloor} (-1)^j \binom{m}{j} \binom{n-kj-1}{m-1}. \]

Combining gives the finite-sum closed form

\[ P(n)=\sum_{m=\lceil n/k\rceil}^{n} \left(\frac{1}{k}\right)^m \sum_{j=0}^{\left\lfloor\dfrac{n-m}{k}\right\rfloor} (-1)^j \binom{m}{j} \binom{n-kj-1}{m-1}. \]

5. Special checks

  • k=1: then the only draw is 1, so \(P(n)=1\) for every \(n\).
  • Small k: for k=2 the recurrence becomes \(P(n)=(P(n-1)+P(n-2))/2\) with \(P(0)=1,P(-1)=0\), etc.

6. Small numerical example (corrected)

Take \(k=6\) (uniform on \(\{1,\dots,6\}\)) and compute \(P(n)\) up to \(n=10\) using the recurrence \(P(n)=\tfrac{1}{6}\sum_{i=1}^{6}P(n-i)\) with \(P(0)=1\) and \(P(m)=0\) for \(m<0\).

Exact rational values and decimals

P(0) = 1 = 1.0000000000

The post Running Sum of Randomly Generated Numbers appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
https://www.anujvarma.com/running-sum-of-randomly-generated-numbers/feed/ 0
Statistical Fallacies and Probability Teasers https://www.anujvarma.com/statistical-fallacies-and-probability-teasers/ https://www.anujvarma.com/statistical-fallacies-and-probability-teasers/#respond Mon, 04 Jul 2016 22:44:00 +0000 http://www.anujvarma.com/?p=4827 Under construction Stock Trading – Incorrect Probability Conclusion Stock can either go up , down or stay still. Hence, probability of any one stock going down is 1/3 rd. Soldiers […]

The post Statistical Fallacies and Probability Teasers appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
Under construction

Stock Trading – Incorrect Probability Conclusion

Stock can either go up , down or stay still. Hence, probability of any one stock going down is 1/3 rd.

Soldiers and Shell Bunkers – Incorrect Assumption

WW 1 soldiers were encouraged to get into fresh bunker shell holes – since it was deemed improbable that a shell would strike the same place twice. Incorrect- since , once the first event has occurred , it’s probability is 1 ! So , it doesn’t reduce from the joint probability of two events . Example- ace drawn from deck , then placed back . What is the probable that it will be drawn again? 1/52 ( not 1/52 times 1/ 52 cause first event has happened already)

The birthday problem

You need only 70 people in a room to have a 99.9 % chance of two common birthdays. You need just 23 for a 50% chance.

Are some runs more probable than others? (Is Chance lumpy  ?)

That is, if you flip a coin 1000 times, will you get more runs of 5 Heads than one would normally expect?

Simpson’s paradox – different sized groups

You solved 9 out of 10 problems, your friend solved 1 out of 1. His success rate was 100% yours was 90%. On day 2, you solved 0 out 1 and he solved 1 out of 2 – his success rate was 50%. Each day, his success rate was higher than yours.  This leads most people to believe that he had the better success rate overall (over the two days). However, over 2 days, you solved 9 out of 11 problems (82 % success), whereas he had 2 out of 3 (67 %). Thus, despite your friend solving a higher proportion of problems on each day, you actually won the challenge !

What if these were Clinical Trials instead of exam problems ? Important to understand the combined effect of multiple days.

The prosecutor’s fallacy

Confusion between two concepts –

  • the probability of an individual matching the description of the perpetrator
  • the probability of an individual (matching the description) of being guilty

Probability of an accused with the same description  – 1 in half a million ( 0.000002 ). 

When you bear in mind that the total population being dealt with is 10 million, 1 in half a million easily translates into 20 possible suspects.

The accused is one of 20 possible suspects – and the chance of his innocence is 19 in 20, not 1 in half-a-million. At least until they have an alibi for the remaining 19 people for that day and time.

The post Statistical Fallacies and Probability Teasers appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
https://www.anujvarma.com/statistical-fallacies-and-probability-teasers/feed/ 0
A probability problem – will these two friends ever meet? https://www.anujvarma.com/a-probability-problem-will-these-two-friends-ever-meet/ https://www.anujvarma.com/a-probability-problem-will-these-two-friends-ever-meet/#respond Fri, 23 Dec 2011 13:30:45 +0000 http://www.anujvarma.com/a-probability-problem-will-these-two-friends-ever-meet/ Two friends decide to meet at a definite place between 9 AM and 10 AM. The first to arrive waits for his friend for 15 minutes and then leaves. If […]

The post A probability problem – will these two friends ever meet? appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
Two friends decide to meet at a definite place between 9 AM and 10 AM. The first to arrive waits for his friend for 15 minutes and then leaves. If each of them arrives at an arbitrary moment between 9 and 10 AM, find the probability that they will meet.

First Step – Sample Space

We can treat this problem geometrically. The interval from 9:00 AM to 10:00 AM represents a segment of length 1. Let a unit length segment on the x axis represent one friend’s sample space. Let a unit segment on the y axis represent the other friend’s sample space. The total sample space is then an area of unit length squared. Every point in this unit square represents the arrivals of the two friends.

Geometric Interpretation of the condition

The events(x,y) during which the friends actually meet are given by the condition

(1)   \begin{equation*} |x - y|\leq \frac{1}{4} \end{equation*}

Solution

The intersection of the above band with the unit square gives us the required probability (7/16)

Related Problems

  1. Two points A and B are thrown at random onto a unit segment of the x axis. Find the probability that the length of the segment will be smaller than the distance between the origin and the nearest point
  2. Buffon’s needle problem –A plane is ruled with parallel straight lines a distance a apart. A needle of length where l < a  is thrown on the plane at random. Find the probability that the needle will hit any of the lines.

The post A probability problem – will these two friends ever meet? appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
https://www.anujvarma.com/a-probability-problem-will-these-two-friends-ever-meet/feed/ 0