Skip to content

Commit

Permalink
update Selection Sampling readme to match code
Browse files Browse the repository at this point in the history
  • Loading branch information
mnespor committed Oct 7, 2017
1 parent a1d0e3f commit bed042c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Selection Sampling/README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,17 @@ func select<T>(from a: [T], count requested: Int) -> [T] {
var b = [T]()

while selected < requested { // 1
examined += 1

let r = Double(arc4random()) / 0x100000000 // 2

let leftToExamine = a.count - examined + 1 // 3
let leftToExamine = a.count - examined // 3
let leftToAdd = requested - selected

if Double(leftToExamine) * r < Double(leftToAdd) { // 4
selected += 1
b.append(a[examined - 1])
b.append(a[examined])
}

examined += 1
}
return b
}
Expand Down

0 comments on commit bed042c

Please sign in to comment.