Skip to content

Instantly share code, notes, and snippets.

@neesenk
Created December 4, 2010 13:12
Show Gist options
  • Save neesenk/728172 to your computer and use it in GitHub Desktop.
Save neesenk/728172 to your computer and use it in GitHub Desktop.
生成集合中的一个随机子集
/* 输出[0..n-1]的一个随机子集m */
void randselect(int *a, int m, int n)
{
while (m > 0) {
if (random() % n-- < m)
a[--m] = n;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment