This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Is there a quick way generate 16 random numbers each iteration with no duplicates? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Is there a quick way generate 16 random numbers each iteration with no duplicates?" Watch "Is there a quick way generate 16 random numbers each iteration with no duplicates?" New topic
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
    
  19

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
    
    4
Please look at this thread about a similar problem.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Is there a quick way generate 16 random numbers each iteration with no duplicates?
 
Similar Threads
how to use Random( )?
Need help understanding math.random method.
about random.next int();
NX: a little more locking don't do no harm...
Hi guys - can someone help me?