3 ms·
"The point isn't that there's something wrong with using the no-argument constructor for Random." This point was never mentioned in your original post. Instead
by chubbard 17y ago
"The point isn't that there's something wrong with using the no-argument constructor for Random."
This point was never mentioned in your original post. Instead ran off and started talking about seeding issues which was completely not related to the original topic.
If your problem was creating a new instance every time you get a random number it seems extremely trivial to remedy that (using Random or SecureRandom).
Random rand = new Random();
for( int i = 0; i < 10000; i++ ) {
numbers[i] = rand.nextInt( x );
}
That seems very obvious if efficiency is your issue here!
"To be clear: I wasn't objecting to lucifer's suggestion of using nextInt and nextBoolean."
This was NOT even close to clear from your original post. It read like your were saying don't use this method because of issues with seeding.
My problem was you were handing out worse advice without any justification because your original post could be misinterpreted as I did. It sounded like you preferred people call Math.random() which was leading them back towards the user unfriendly version Math.random() which is the source of so many bugs when there are better options.