Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to create a number generator that will only pick a number 1 time?
    primarykey
    data
    text
    <p>I am creating a concentration game.</p> <p>I have an buffered image array where I load in a 25 image sprite sheet.</p> <pre><code>public static BufferedImage[] card = new BufferedImage[25]; </code></pre> <p>0 index being the card back. and 1 - 24 being the values for the face of the cards to check against if the cards match.</p> <p>What I am tying to do is this I will have 4 difficulties Easy, Normal, Hard, and Extreme. Each difficulty will have a certain amount of cards it will need to draw and then double the ones it chosen. for example the default level will be NORMAL which is 12 matches so it need to randomly choose 12 unique cards from the Buffered Image array and then double each value so it will only have 2 of each cards and then shuffle the results.</p> <p>This is what I got so far but it always seems to have duplicates about 99% of the time.</p> <pre><code>//generate cards Random r = new Random(); int j = 0; int[] rowOne = new int[12]; int[] rowTwo = new int[12]; boolean[] rowOneBool = new boolean[12]; for(int i = 0; i &lt; rowOneBool.length; i++) rowOneBool[i] = false; for(int i = 0; i &lt; rowOne.length; i++){ int typeId = r.nextInt(12)+1; while(rowOneBool[typeId]){ typeId = r.nextInt(12)+1; if(rowOneBool[typeId] == false); } rowOne[i] = typeId; j=0; } </code></pre> <p><img src="https://i.stack.imgur.com/oojpf.png" alt="A sample run of my program"></p> <p>the 3 amounts I will be needing to generate is Easy 6, Normal 12, and Hard 18 extreme will use all of the images except index 0 which is the back of the cards.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload