• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 23928
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 76862
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please look at this thread about a similar problem.
 
Ruth Stout was famous for gardening naked. Just like this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic