mardi 7 avril 2015

How do I create a fixed-length list of random values within a given range without triplicates?

Even though the title says something a bit different from what i intend to find out, i had to keep it short and raise interest in this, because my question is more specific.


I've got an array of numbers from 1 to 13, randomly generated, the array's lenght being 15. I've also got a string of letters, whose lenght is also 15, randomly chosen from the set {"a", "g", "n", "r"}.


Let's call the array "number[i]" and the string "letter[i]". Now i associate the 2 concepts, without creating a struct, just imagine elements like 1a, 1r, 12n, 5g...


The question is: How can i change (of course i must verify this first) values that occur 3 or more times so that in the end i get only (maximum) 2 occurences like: number[5]=12, letter[5]="a", number[8]=12, letter[8]="a"; - no other number[i]=12 && letter[i]="a" for any i<=15 i!=8 and 5.


Hope it's clear because i ask a lot.





Aucun commentaire:

Enregistrer un commentaire