Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By JosAH

Thread: Need advice on how to Randomly change elements in an array ?? HELP...

  1. #1
    Join Date
    Dec 2013
    Location
    Dublin
    Posts
    32
    Rep Power
    0

    Question Need advice on how to Randomly change elements in an array ?? HELP...

    Hi
    I am relatively new to Java and would welcome any help on this matter. I am working on a personal project to be able to show in a college interview as part of a portfolio. I am creating a program that will simulate a tournament draw. I have an initializer array with 26 teams available in it. I am in the early stages of the project and I am trying to figure out the algorithm to the app.

    For the moment I will not be continuing with the user interface until I can ensure the app will work.

    So the program runs:

    An list of teams is output alongside index numbers;

    The user is prompted to select the number of participants in the tournament;
    Then the user is prompted to select their teams by inputting the corresponding index numbers;

    While I am testing I have the selected teams output on screen. Now comes my problem: I want to randomly arrange the users teams which are elements on an array. I have tried many variations of if, while, and do while statements. I am getting them to randomise but the problem is that at least one element duplicates every time.

    I hope my problem is clear.

    I need to randomly change the index of elements on an array without duplicating etc.

    Any help would be greatly appreciated.
    Last edited by Castro__711; 12-17-2013 at 08:15 PM.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,375
    Blog Entries
    7
    Rep Power
    20

    Default Re: Need advice on how to Randomly change elements in an array ?? HELP...

    I bet you're using arrays for your teams; don't do that, use Lists instead; the Collections utility class can shuffle the elements of a List.

    kind regards,

    Jos
    Castro__711 likes this.
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Join Date
    Dec 2013
    Location
    Dublin
    Posts
    32
    Rep Power
    0

    Default Re: Need advice on how to Randomly change elements in an array ?? HELP...

    You are right I am using arrays. Thank you very much. :)

Similar Threads

  1. Replies: 0
    Last Post: 05-02-2013, 09:19 AM
  2. Sum up elements in an array?
    By D-X69 in forum New To Java
    Replies: 3
    Last Post: 05-30-2012, 04:23 PM
  3. How to Randomly call objects in an Array?
    By Murd in forum New To Java
    Replies: 12
    Last Post: 11-30-2011, 04:12 AM
  4. Replies: 3
    Last Post: 11-25-2011, 12:38 AM
  5. Help with array of elements
    By zoe in forum New To Java
    Replies: 1
    Last Post: 07-24-2007, 05:33 PM

Tags for this Thread

Posting Permissions

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