• Post Reply Bookmark Topic Watch Topic
  • New Topic

Is there a quick way generate 16 random numbers each iteration with no duplicates?  RSS feed

 
Dick Hammer
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Campbell Ritchie
Marshal
Posts: 56581
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please look at this thread about a similar problem.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!