Hello,
It’s first time I need help.
I try to create a randomize system with range int (1-5) this thing works. But I need to repeat this, but I don’t want reapeat the same number
if the number is 3 for example the new draw can’t choose 3 again
When all numbers are choose one time repeat this from the begining.
The goal of this it’s obtain a the randomize of 5 elements but with the same number of occurence in 20 draw 4 for each number.
Thank of your help if you take the time to help me.
The best way to do this is put all of your values into an array:
int numberOfValues = 5;
int[] values = new int[numberOfValues];
for (int i = 0; i < numberOfValues; i++) {
values[i] = i + 1;
}
Then run the array through a shuffle algorithm to put it in a random order. Here’s an example which you can just copy and use: https://www.dotnetperls.com/fisher-yates-shuffle
Then you can just pull the elements from the array one by one. When all numbers are chosen, shuffle the array again and start over.
1 Like
Hey I had a typo in my code above so if you’re using it check the updated version!