In Java we have static class Math. You don’t need to create its objects so its static. Another one is Random class. We don’t need to create its instances so why isn’t it static too? My classes I often use random numbes and get mad when have to create field rand in every class to generate random numbers. So why isn’t it static?
Share
The Random class has state, including where it is in its sequence, as the values produced are not truly random, just a pseudo-random sequence.
This can be demonstrated by initialising two instances with the same seed.
Output
If you create with the default constructor Random(), then the seed is initialized based on the current time in nanoseconds + a static counter, which means different instances are very likely to have different sequences.