2

What's the best way to produce a weighted die roll in Swift, given the following percentages?

var weight = [0.1, 0.2, 0.2, 0.3, 0.1, 0.1]

e.g. There's a 10% chance it will roll a 1, 20% chance for a 2, etc.

Justin Lewis
  • 534
  • 1
  • 5
  • 22
  • 1
    I think the referenced thread should be what you are looking for. Otherwise let me know and I'll reopen the question. – Martin R Jul 07 '15 at 16:19
  • Thanks! I couldn't find the answer in Swift, so I'd post it. I should've been searching for "distribution" instead of "weighted" – Justin Lewis Jul 07 '15 at 16:41
  • I think both are valid terms. I just happened to know about this Q&A :) – Martin R Jul 07 '15 at 16:50

0 Answers0