Knuth's algorithm S: Difference between revisions
Content added Content deleted
(Updated D code) |
|||
Line 342: | Line 342: | ||
if i <= n |
if i <= n |
||
sample << item |
sample << item |
||
elsif rand < |
elsif rand < (n.to_f/i) |
||
sample[rand(n)] = item |
sample[rand(n)] = item |
||
end |
end |