Knuth's algorithm S: Difference between revisions
Content added Content deleted
(added C) |
|||
Line 329:
=={{header|Python}}==
{{works with|Python|3.x}}
<lang python>from random import randrange
Line 405 ⟶ 406:
elif randrange(i) < n:
# Keep item
return sample</lang>
The above can be instantiated as follows after which <code>s_of_n</code> can be called in the same way as it is in the first example where it is a function instead of an instance.
|