I was reading java.util.Random class and noticed that there is no nextDouble(), nextFloat() and nextLong() which can accept a bound.
There are many way to get it done like this.
But my question is why java did not provide us with these required method like nextInt(int n) which accept the bound.
Is there any specific reason they did not provide these methods?
A good API always tries to provide the essential elements that a user needs to do his job.
Having nextInt(int n) is just one possible implementation. What if you need other distributions?!
In other words: the Random API could try to anticipate all potential usage patterns, but that would very much bloat the whole API. Instead, the designers choice a very small interface - but you got all the elements required to build your own things on top of that.
Thing is: in the end, this is a design style decision by the people who created the Random class. And as so often, problems could be solved in many different ways. Thus you shouldn't draw deep conclusions on the solution that was picked here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With