Results 1 to 2 of 2
  1. #1
    dcarter's Avatar
    dcarter is offline Student
    Join Date
    Sep 2014
    Location
    NC
    Posts
    14
    Rep Power
    0

    Default How to "shuffle" an array using random numbers?

    For a project we have to "shuffle" items in an array using random numbers. We are supposed to generate random numbers and use those numbers to exchange array elements. But I am not sure what that means, "exchange array elements". Does that mean you generate 2 random numbers within the length of the array, and then switch the items at those locations in the array? I don't know how I'd do that. Help?

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: How to "shuffle" an array using random numbers?

    There are several threads on shuffling in this forum. Just search for them. Let's say you have three boxes, all the same size. And two of them are filled with stuff. How do you swap the contents of the two boxes? Once you figure that out you can do the same with array elements.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Replies: 3
    Last Post: 01-26-2013, 03:49 AM
  2. Replies: 0
    Last Post: 12-07-2012, 08:29 AM
  3. Replies: 5
    Last Post: 10-24-2012, 09:17 PM
  4. 2D Array Random Shuffle
    By Nuluvius in forum New To Java
    Replies: 8
    Last Post: 11-23-2008, 06:15 PM
  5. Help with code "perfect shuffle"
    By trill in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 07:25 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
  •