Re: Chances of (random(0,n) + random(0,n) <= m)
mensanator_at_aol.com
Date: 11/03/04
- Next message: Eric Gisse: "Re: Uncle assAl: (SR) Lorentz t', x' = Intervals"
- Previous message: Stan Brown: "Re: Chances of (random(0,n) + random(0,n) <= m)"
- In reply to: Brendan Sechter: "Chances of (random(0,n) + random(0,n) <= m)"
- Next in thread: poespam-trap_at_yahoo.com: "Re: Chances of (random(0,n) + random(0,n) <= m)"
- Messages sorted by: [ date ] [ thread ]
Date: 3 Nov 2004 14:08:19 -0800
Brendan Sechter wrote:
> If I am going pick two numbers at random, both from zero to n and add
> them, what is the chance of the sum being less than or equal to m?
>
> This seems like it should be easy, but my math is really rusty.
>
> If n is 5 and m is 3 I can draw this diagram:
>
> | m n
> |0 1 2 3 4 5
> -----+-----------------------
> |
> 0 |0 1 2 3 / 4 5
> | /
> 1 |1 2 3 / 4 5 6
> | /
> 2 |2 3 / 4 5 6 7
> | /
> m 3 |3 / 4 5 6 7 8
> | /
> 4 |4 5 6 7 8 9
> |
> n 5 |5 6 7 8 9 10
>
> The chance of the random sum being less than m is 10 / 25.
Two mistakes:
First: 10 would be for <=m not <m (which would be 6)
Second: denominator is 36 not 25. It's not n^2 because you're
counting from 0, so it should be (n+1)^2.
> If m is
> less than or equal to n, the chances are 0 + 1 + ... m + (m + 1).
Use the sum of integers formula (adjusting for counting from 0):
sum(m+1) = ((m+1)^2 + (m+1))/2
So for m=3, you get ((3+1)^2 + (3+1))/2 = (4^2 + 4)/2 = 20/2 = 10
>
> If m is greater than n, the chances are n squared minus something. I
> can see the "something", but I'm having trouble putting it in terms
of
> m and n. I'm also not happy with an if-else answer.
It's symmetric. Instead of breaking off the corner of the square and
keeping it, you break off the opposite corner and discard it.
Keeping the corner is the SumOfIntegers. Discarding it is
(n+1)^2 - SumOfIntegers.
But you'll need an if-else to decide which to use.
Summarizing, if
m<n
probability of <m = sum((m+1)-1) / (n+1)^2
probability of <=m = sum((m+1)) / (n+1)^2
probability of =m = (m+1) / (n+1)^2
probability of >=m = (n+1)^2 - sum((m+1)) / (n+1)^2
probability of >m = (n+1)^2 - sum((m+1)-1) / (n+1)^2
m=n
probability of <m = sum((m+1)-1) / (n+1)^2
probability of <=m = sum((m+1)) / (n+1)^2
probability of =m = (m+1) / (n+1)^2
probability of >=m = sum((m+1)) / (n+1)^2
probability of >m = sum((m+1)-1) / (n+1)^2
m>n
probability of <m = (n+1)^2 - sum((m+1)-1) / (n+1)^2
probability of <=m = (n+1)^2 - sum((m+1)) / (n+1)^2
probability of =m = (m+1) / (n+1)^2
probability of >=m = sum((m+1)) / (n+1)^2
probability of >m = sum((m+1)-1) / (n+1)^2
>
> Side note: What is my real problem?
> This is a death spell calculation that may be used in a game. n is
> the spell's power level and m is the target's remaining life. It
> would be nice to be able to display the chance of killing the target.
> It's not strictly necessary that I understand why a given solution
> works, but as a matter of personal pride I'd like to.
>
> -Brendan
- Next message: Eric Gisse: "Re: Uncle assAl: (SR) Lorentz t', x' = Intervals"
- Previous message: Stan Brown: "Re: Chances of (random(0,n) + random(0,n) <= m)"
- In reply to: Brendan Sechter: "Chances of (random(0,n) + random(0,n) <= m)"
- Next in thread: poespam-trap_at_yahoo.com: "Re: Chances of (random(0,n) + random(0,n) <= m)"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|