取随机率的问题
要取一个10%de随机率 暂时有几种想法 不知道那种更理想或者都不行
1.int x = rand()%100; if(x<10){return true;}
2.int x = rand()%90;
int y = rand()%100;
if(y>=x&&y<x+10){return true;}
3.int K[10] ;
int i = 0;
bool issame = false;
while(i < 10){
int index = rand()%100;
for(int j = 0;j<i;j++){
if(index == k[j]){
issame = true;
}
}
if(!issame){
k[i] = index;
i++;
}
}
int x = rand()%100;
for(int m = 0;m<i;m++){
if(x == K[m]){
return true;
}
}