vendredi 28 septembre 2018

Generate random array of integers with a number of appearance of each integer

I need to create a random array of 6 integers between 1 and 5 in Python but I also have another data say a=[2 2 3 1 2] which can be considered as the capacity. It means 1 can occur no more than 2 times or 3 can occur no more than 3 times.

I need to set up a counter for each integer from 1 to 5 to make sure each integer is not generated by the random function more than a[i].

Here is the initial array I created in python but I need to find out how I can make sure about the condition I described above. For example, I don't need a solution like [2 1 5 4 5 4] where 4 is shown twice or [2 2 2 2 1 2].

solution = np.array([np.random.randint(1,6) for i in range(6)])

Even if I can add probability, that should work. Any help is appreciated on this.




Aucun commentaire:

Enregistrer un commentaire