this post was submitted on 31 Aug 2026
24 points (96.2% liked)
Programming
28399 readers
355 users here now
Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!
Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.
Hope you enjoy the instance!
Rules
Rules
- Follow the programming.dev instance rules
- Keep content related to programming in some way
- If you're posting long videos try to add in some form of tldr for those who don't want to watch videos
Wormhole
Follow the wormhole through a path of communities !webdev@programming.dev
founded 3 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
The probability of going for
prepeats without hitting the lower end of the range is((N - M) / N) ^ pwhereNis the size of the input range andMis the size of the largest integer multiple of the output range, which falls exponentially towards zero aspincreases, so the chance of the process not terminating is zero.With OP's example, with an input range of 256 and an output range of 202, this would mean the probability of making 10 unsuccessful attempts would be
(54/256) ^ 10 = 0.00000017or about 1 in 6 million. The probability of making 20 unsuccessful attempts would be 1 in 36 trillion, and so on.