| Author |
Is there a quick way generate 16 random numbers each iteration with no duplicates?
|
Dick Hammer
Greenhorn
Joined: Jan 28, 2012
Posts: 18
|
|
Can someone give me an example of how to use collections.shuffle on an ArrayList so that I can generate 16 non-repeating random numbers....er I mean "random" numbers. I've read up on generating non-repeating random numbers but it just complicated things (Like someone pointing out that non-repeating random numbers are not technically random because random numbers do repeat. *face to palm* For ****'s sake ok? *simulates blowing his brains out* Yah, ok I get that it's not random, but you know what I am getting at, yeah? Random numbers from a declining population...however you want to think about it. And besides, it IS random...the sequence will not be random, but each iteration the selection of a number (from a narrowing range) is random so forgive my sloppy terminology...grrr...you get the point...I'm trying to write a little proggie that will display 16 images on the screen in a 4x4 array but each iteration the order of the cards or images is random. I would really appreciate any help. What's the best way to go about this? I have searched and like I said I found info including "shuffle" but it gets vague and could not find good examples. I want to know how to drive a car and I found explanations of internal combustion, ya know what I mean? Cheers.
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16687
|
|
Dick Hammer wrote:Can someone give me an example of how to use collections.shuffle on an ArrayList so that I can generate 16 non-repeating random numbers....er I mean "random" numbers. I've read up on generating non-repeating random numbers but it just complicated things (Like someone pointing out that non-repeating random numbers are not technically random because random numbers do repeat. *face to palm* For ****'s sake ok? *simulates blowing his brains out*  Yah, ok I get that it's not random, but you know what I am getting at, yeah? Random numbers from a declining population...however you want to think about it.  And besides, it IS random...the sequence will not be random, but each iteration the selection of a number (from a narrowing range) is random so forgive my sloppy terminology...grrr...you get the point...I'm trying to write a little proggie that will display 16 images on the screen in a 4x4 array but each iteration the order of the cards or images is random. I would really appreciate any help. What's the best way to go about this? I have searched and like I said I found info including "shuffle" but it gets vague and could not find good examples. I want to know how to drive a car and I found explanations of internal combustion, ya know what I mean? Cheers.
Not sure what to explain, as it is straightforward -- just put all 16 unique image objects into a list collection. And then call the shuffle() method of the Collections class to randomly shuffle it into a different order.
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32651
|
|
|
Please look at this thread about a similar problem.
|
 |
 |
|
|
subject: Is there a quick way generate 16 random numbers each iteration with no duplicates?
|
|
|