In a Sequence of n number of lights, every light has an x % probability of being lit or not. I need a way to calculate the probability of 0 lights being lit at once, only 1 light lit, 2 lights lit at once... n lights lit at once.

I hope I'm making myself clear, here is an example given that probability x is 25%

If n == 1

  • 0 lights: 3/4 Probability
  • 1 light: 1/4 Probability

If n == 2

  • 0 lights: 9/16
  • 1 light: 6/16
  • 2 lights: 1/16

If n == 3

  • 0 lights: 27/64
  • 1 light: 27/64
  • 2 lights: 9/64
  • 3 lights: 1/64


I wrote a script that simulates all possibilities and counts the results however it's obviously not efficient at all and I have not managed to excrete any useful patterns.

Is there an efficient way to get these probabilities?


2 Answers 2


Let M be the random variable representing the number of lights being lit then,

$P(M=m) = {n \choose m}x^m{(1-x)}^{n-m}$

Basically $M \sim Binomial(n,x)$

  • $\begingroup$ Sorry for commenting here, but since I had no other way to contact, the recent answer which you deleted was correct, I suppose, and easier. Could you please repost it? Please flag this comment as unimportant after you read it. Thanks! $\endgroup$
    – Iceberry
    May 2, 2018 at 2:47

You're in luck, and asked at the right place. This is a standard problem for a binomial distribution: https://en.wikipedia.org/wiki/Binomial_distribution

Here's the formula you want for the probability that $k$ lights from $n$ are on. In your example $p = 0.25$.

$$ Pr(k;n,p)=\Pr(X=k)={n \choose k}p^{k}(1-p)^{n-k} $$

for $k = 0, 1, 2, ..., n$, where

$$ \binom {n}{k}=\frac {n!}{k!(n-k)!} . $$


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .