Lachesis has provided the details
it in this post.
P(p,t)=1-e^(-pt)
Where p is the probability that you will win in one second: p=khps*1000*target/2^256, and t is the number of seconds.
So I solved for t:
t = -ln(1-P)/p
Llama agrees
in this post.
To calculate average (expected value of generation time):
1/(pr)
To calculate how long until you have a T chance of producing at least 1 block:
-ln(1-T)/pr
Where:
p = probability of a given hash resulting in success (TARGET / 2^256)
r = rate in hashes / sec
T = target probability, such as 0.95
ln = log base e
What lachesis and llama call "target" is Bitcoin's hashing difficulty factor (currently 109670 but due to increase in the next day or so).