code_junkie

Efficiently selecting a set of random elements from a linked list

Nov 10th, 2011
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.15 KB | None | 0 0
  1. List GetKRandomFromList(List input, int k)
  2. List ret = new List();
  3. for(i=0;i<k;i++)
  4. ret.Add(input[Math.Rand(0,input.Length)]);
  5. return ret;
Add Comment
Please, Sign In to add comment