There are better strategies for returning random numbers in a range, in terms of the fraction of values that will be rejected.<p>The code shown here recognizes the problem (the example of generating numbers from 0 to 25 inclusive) and finds a construct that makes things better (the modulo some-power-of-two step), but it's possible to do better and have nearly no rejections.<p>Here's a really good tutorial on some further steps that can be taken to reduce the quantity of numbers sampled, and make it faster to reject unusable numbers:<p><a href="https://sts10.github.io/2020/10/10/lemire-neaarly-divisionless-random.html" rel="nofollow noreferrer">https://sts10.github.io/2020/10/10/lemire-neaarly-divisionle...</a><p>However, the initial / best example assumes that 128 bit arithmetic types are available and reasonably efficient and I think that may not even be true in typescript(?).