//求解0-n中(包含0,但不包含n)m个不重复随机数的算法.
- C/C++ code
-
void knuth(int n, int m) { srand( (unsigned)time( NULL ) ); for( int i = 0; i < n; i++) { if( rand()%(n-i) < m) { cout << i << "\t"; m--; }// end if }//end for return; }