Efficiently selecting a set of random elements from a linked list

Posted by Matt Sheppard on Stack Overflow See other posts from Stack Overflow or by Matt Sheppard
Published on 2008-09-10T13:40:48Z Indexed on 2010/04/06 6:03 UTC
Read the original article Hit count: 259

Say I have a linked list of numbers of length N. N is very large and I don’t know in advance the exact value of N.

How can I most efficiently write a function that will return k completely random numbers from the list?

© Stack Overflow or respective owner

Related posts about language-agnostic

Related posts about algorithm