My code works, But how do I make this code run in a deterministic time?
Your code is determinstic: it uses no randomness. But I assume you want the running time to be essentially independent of the input.

Assuming I've understood the problem correctly, you're dropping a ball from height h and, when dropped from height x, it bounces to height x*Bouncefactor. You want to know how many times it passes through the height you're calling window.  Your approach is, essentially, to simulate the bouncing ball and count.

Instead of doing that, you should just calculate how many times the ball bounces before it's at height less than window.  This is the least k such that h * Bouncefactor^k &lt; window, so you just need to solve this equation and then convert the number of bounces into the number of times that the ball is seen.