+ 1
How can i make a random value without duplication of value in each in dex of array?
random value in each index of array
3 Réponses
+ 1
https://msdn.microsoft.com/en-us/library/aa990145(v=vs.80).aspx
you may use Random.nextInt to generate a random number.
then use Array.Contains to check if the random generated is already there or not.
you may use an infinite loop to create a process of checking the number if was already on the array amd generate a new random number until the generated random number is not already taken and stop the loop.
+ 1
i have tried it already but the form is freezing and your reference is 2005 im using 2010. there is no nextint but instead next only.
+ 1
oh. sorry for the nextInt.
ahhmm.
I think, instead of infinite loop, you could try do while. here is the sample.
Random r = new Random();
do{
iNumb = r.Next();
} while (yourArray.Contains(iNumb);
then add the iNumb to you array after the loop. :)