0

Say I have some probabilities that happen to add up to 1

prob=[.80,.10,.05,.02,.02,.01]

that correspond to the elements

elements=["A","B","C","D","E","F"]

And I want to randomise the list so that each element has their probability of being picked and put into the firstmost available slot, but once picked is not picked again.

I searched StackOverflow but I could only find either selecting elements totally at random or only selecting a single item with a weighted random.

BaconCatBug
  • 137
  • 9
  • 1
    Using `numpy`: `np.random.choice(elements,len(elements),replace=False,p=prob)` – sacuL Oct 23 '18 at 22:07
  • the numpy one works as random.sample() with propability due to `replace=False` ? - nevermind it does - its even in the dupes answers – Patrick Artner Oct 23 '18 at 22:16

0 Answers0