Created
December 4, 2010 13:12
-
-
Save neesenk/728172 to your computer and use it in GitHub Desktop.
生成集合中的一个随机子集
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 输出[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