As you may know, Random.nextLong()
does not generate all possible long values in Java. How can I check if a specific long is randomly generatable by that method?
Asked
Active
Viewed 50 times
-1
-
Why do you want to know that? That sounds like an [XY problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). – Progman Mar 06 '21 at 16:48
1 Answers
1
First, the JavaDoc to Random says:
The implementation of {@code setSeed} by class {@code Random} happens to use only 48 bits of the given seed. In general, however, an overriding method may use all 64 bits of the {@code long} argument as a seed value.
But you may also want to check out ThreadLocalRandom since it does not appear to have the 48 bit seed limit. And it is also faster.

WJS
- 36,363
- 4
- 24
- 39