Here's my ramdomize code:
int monstername;
monstername = rand() % 3;
but I want 0 with 70% of output 1 with 20% 2 with 10% how I can do this with C?
int monstername;
int random_var = rand() % 10;
if(random_var < 7) {
// 0-70%
monstername = 0;
}
else if(random_var < 9) {
// 70-90% here
monstername = 1;
}
else {
// 90-100% here
monstername = 2;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With