Skip to main content

Timeline for get weighted random item

Current License: CC BY-SA 4.0

9 events
when toggle format what by license comment
Jul 29, 2019 at 12:35 comment added Patrick Klug +1 Just a word of caution to anyone using this: weightFunc should return a positive number as the above method won't work with negative weights.
S Nov 7, 2018 at 9:18 history suggested Ghost4Man CC BY-SA 4.0
improved formatting and marked code block as C#
Nov 6, 2018 at 20:00 review Suggested edits
S Nov 7, 2018 at 9:18
Jul 20, 2018 at 10:10 comment added Deduplicator Nice solution if you really only have to choose once. Otherwise, doing the prep-work for the solution in the first answer once is far more efficient.
Feb 15, 2016 at 8:23 comment added Jim Yarbro I just wanted to say I've come back to this thread 3 or 4 times in the last couple years to use this method. This method has repeatedly succeeded in providing the answers I need quickly enough for my purposes. I wish I could upvote this answer every time I came back to use it.
Jul 21, 2015 at 19:33 comment added Vivin Paliath Should be the accepted answer imo. I like this better than the "interval" and "repeated entry" approach.
Jun 21, 2013 at 7:28 comment added Nevermind @Jean-Bernard Pellerin I did, and it is actually faster on large lists. Unless you use cryptographically strong random generator (-8
Jun 20, 2013 at 22:59 comment added Jean-Bernard Pellerin I would benchmark this before assuming it's better just because it iterates once. Generating just as many random values isn't exactly fast either.
May 29, 2012 at 11:38 history answered Nevermind CC BY-SA 3.0