Skip to content

Commit bed042c

Browse files
committed
update Selection Sampling readme to match code
1 parent a1d0e3f commit bed042c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Selection Sampling/README.markdown

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,17 @@ func select<T>(from a: [T], count requested: Int) -> [T] {
8989
var b = [T]()
9090

9191
while selected < requested { // 1
92-
examined += 1
93-
9492
let r = Double(arc4random()) / 0x100000000 // 2
9593

96-
let leftToExamine = a.count - examined + 1 // 3
94+
let leftToExamine = a.count - examined // 3
9795
let leftToAdd = requested - selected
9896

9997
if Double(leftToExamine) * r < Double(leftToAdd) { // 4
10098
selected += 1
101-
b.append(a[examined - 1])
99+
b.append(a[examined])
102100
}
101+
102+
examined += 1
103103
}
104104
return b
105105
}

0 commit comments

Comments
 (0)