#include <stdio.h> #include <stdlib.h> #include <time.h> #define N 5 #define N1 80 #define N2 35 int main(){ int cnt; int r;//random_major,random_no; srand(time(NULL)); //new:未被选的人员数 int u1=N1,u2=N2; cnt=0; while(cnt < N) { // random_major = rand()%2; // if(random_major){ // random_no = rand()%N1+1; // printf("20256343%04d\n",random_no); // }else{ // random_no=rand()%N2+1; // printf("20256136%04d\n",random_no); // } // cnt++; //假如我想等比例分层抽样,同时防止重复,可以: cnt++; r=rand()%(u1+u2)+1;//[1,u1+u2] if(r<=u1){//[1,u1] printf("20256343%04d\n",r); u1--; }else{//[u1+1,u1+u2] printf("20256136%04d\n",r-u1); u2--; } } return 0; }