1. Member
Join Date
Jul 2012
Posts
10
Rep Power
0

## Java question.

I am trying to uniformly distributed int value as low as 0 and as high as n . Therefore, nextInt(songs.size()) gives you a random index. the size of songs lessens by one each time you add a randomly selected song to newList. I have to account for this each time you generate a random number.

This is code I have.

public int random (int ){
newList = new ArrayList<Mp3>();
nt randomIndex = random.nextInt(songs.size());
if (songs.size() > 0) {
songs.randomSongs = songs.remove(0);

Thanks.

2. ## Re: Java question.

I'm sorry, what exactly is your question? Can you clarify just where you're stuck for us?

Also, consider making your question heading more informative as well. "Java question" doesn't tell us much of anything other than that you have a Java question -- but we knew that already, else you wouldn't be here.

3. Member
Join Date
Jul 2012
Posts
10
Rep Power
0

## Re: Java question.

Originally Posted by Fubarable
I'm sorry, what exactly is your question? Can you clarify just where you're stuck for us?

Also, consider making your question heading more informative as well. "Java question" doesn't tell us much of anything other than that you have a Java question -- but we knew that already, else you wouldn't be here.

Good Day,

Trying to do a combination of using shuffle and random for songs
newList is where the songs will be removed from then added back to the end of the newList.

4. Member
Join Date
Jul 2012
Posts
10
Rep Power
0

## Re: Java question.

The code I have posted.

5. ## Re: Java question.

I think you'll likely get better help if you explain yourself in greater detail. You may be assuming that we can guess more about your problem then we really are able to.

6. Member
Join Date
Jul 2012
Posts
10
Rep Power
0

## Re: Java question.

The shuffle random number has to be low -2 and high as n.
Last edited by immortal; 08-06-2012 at 04:27 AM.

7. ## Re: Java question.

If you are asking how to randomly play a list of songs then yo need to place all the songs in a List, shuffle, remove first song and play it. Repeat until the List is empty. If you want to play the List again but in a different order then you need to create a new List containing all the songs and repeat the process.

8. Member
Join Date
Jul 2012
Posts
10
Rep Power
0

## Re: Java question.

Originally Posted by Junky
If you are asking how to randomly play a list of songs then yo need to place all the songs in a List, shuffle, remove first song and play it. Repeat until the List is empty. If you want to play the List again but in a different order then you need to create a new List containing all the songs and repeat the process.
Yes. that's it. how would it work if the number has to be -2 and high as n?

9. ## Re: Java question.

The algorithm works the same regardless of how many objects are involved.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•