I want to generate a random, cryptographically secure double in a very large range, say -Double.MAX_VALUE
to Double.MAX_VALUE
.
Based on existing StackOverflow questions (1 2 3 4 5 6) you may think that using min + new SecureRandom().nextDouble() * range
would suffice, but Double.MAX_VALUE - -Double.MAX_VALUE
overflows and becomes infinite!
To solve that, this StackOverflow answer suggests using ThreadLocalRandom.nextDouble(min, max)
. While this method is indeed capable of spanning the range I need it to, this implementation is not cryptographically secure!
How can I securely generate a random number within such a large range?