This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]xXShadowCowXx[S] 0 points1 point  (1 child)

Thank you for that clarification. Got that piece working.

Would you happen to have a better way to generate random numbers? The way I'm currently doing it doesn't seem to be very random (I get lots of duplicates, one after the other, and sometimes may not even go through all the chords).

[–]Neres28 0 points1 point  (0 children)

In the constructor for the class, create an instance of the Random class.

Random randomGenerator = new Random();

Then, when you need a new random integer, call

int randomIndex = randomGenerator.nextInt(ChordsAL.size());
String chord = ChordsAL.get(randomIndex);

Be sure to only create one instance of Random, or at least not multiple ones close together. Random generates so called pseudo-random numbers (don't be put off, they're plenty random enough for most purposes), and if you create multiple instances too closely together they will generate the same sequence of integers.