0

It seems like randomElement() in Swift only allows for an equally weighted selection. What would be the best (and most efficient way, as I need to repeat this very often) to select from a collection with pre-specified probabilities/weights?

Jay
  • 59
  • 6
  • I saw that post, but is that really the most efficient way? It seems quite involved with the for loops etc. As said above, this should be as fast as possible. – Jay Oct 22 '22 at 11:23
  • 1
    [This example](https://stackoverflow.com/a/51122606/1630618) uses multiple copies of the elements to weight the choices and is very fast in specific cases. – vacawama Oct 22 '22 at 11:36

0 Answers0