标签:随机数
<span style="font-size:18px;">srand(time(0)); x=rand();//0~RAND_MAX-1 </span>
x=rand()%(b-a+1)+a;
// This function generates 'x' with probability px/100, 'y' with // probability py/100 and 'z' with probability pz/100: // Assumption: px + py + pz = 100 where px, py and pz lie // between 0 to 100 int random(int x, int y, int z, int px, int py, int pz) { // Generate a number from 1 to 100 int r = rand(1, 100); // r is smaller than px with probability px/100 if (r <= px) return x; // r is greater than px and smaller than or equal to px+py // with probability py/100 if (r <= (px+py)) return y; // r is greater than px+py and smaller than or equal to 100 // with probability pz/100 else return z; }
标签:随机数
原文地址:http://blog.csdn.net/u010367506/article/details/28664759