Results 1 to 9 of 9

Thread: Java question.

  1. #1
    immortal is offline Member
    Join Date
    Jul 2012
    Posts
    10
    Rep Power
    0

    Default 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. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default 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. #3
    immortal is offline Member
    Join Date
    Jul 2012
    Posts
    10
    Rep Power
    0

    Default Re: Java question.

    Quote Originally Posted by Fubarable View Post
    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. #4
    immortal is offline Member
    Join Date
    Jul 2012
    Posts
    10
    Rep Power
    0

    Default Re: Java question.

    The code I have posted.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default 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. #6
    immortal is offline Member
    Join Date
    Jul 2012
    Posts
    10
    Rep Power
    0

    Default 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. #7
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default 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. #8
    immortal is offline Member
    Join Date
    Jul 2012
    Posts
    10
    Rep Power
    0

    Default Re: Java question.

    Quote Originally Posted by Junky View Post
    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. #9
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default Re: Java question.

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

Similar Threads

  1. Hello I have a question about map java
    By yoron1234567 in forum Forum Lobby
    Replies: 2
    Last Post: 03-14-2012, 04:14 PM
  2. Java Question
    By Etimer in forum New To Java
    Replies: 7
    Last Post: 02-04-2012, 07:09 AM
  3. Java Question [Beginner Question]
    By joker760 in forum New To Java
    Replies: 3
    Last Post: 12-13-2011, 04:01 PM
  4. Java question
    By TGH in forum New To Java
    Replies: 12
    Last Post: 11-27-2009, 02:05 PM
  5. question about java rmi
    By hakimade in forum Advanced Java
    Replies: 1
    Last Post: 07-01-2009, 07:15 AM

Posting Permissions

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