Finding random Long number with range in Java
If we have to find a random integer we can use Random() api like this :
If we know the upper bound, we can specify it is one of the parameters like this
So this code will generate any random number between 0 and 1000 excluding 1000.
As there is a method for random integer generation we would have expected a similar method for Long also. Something like this :
Unfortunately it does not exist but fortunately Java7 has a new api for this
Mar Java Mit Java 🙂