mardi 22 janvier 2019

Avoid duplicate random values

Following this post, I can generate random integers with a fixed sum. However, I want to avoid any duplicate numbers (such as 20 in the following example):

import numpy as np

_sum = 100
n = 5
rnd_array = np.random.multinomial(_sum, np.ones(n)/n, size=1)[0]
rnd_array

>>> array([20, 24, 20, 21, 15])

How could I achieve this?




Aucun commentaire:

Enregistrer un commentaire