Will this give me proper random numbers based on these probabilities? C++
Code: int random = (rand() % 7 + 1) if (random == 1) { } // num 1 else if (random == 2) { } // num 2 else if (random == 3 || random == 4) { } // num 3 else if (random == 5 || random == 6) { } // num 4 else if (random == 7) { } // num 5 Basically I want each of these numbers with each of these probabilities: 1: 1/7 2: 1/7 3: 2/7 4: 2/7 5: 1/7 Will this code give me proper results? I.e. if this is run infinite times, will I get the proper frequencies? Is there a less-lengthy way of doing this? derobert Not, it's actually slightly off, due to the way rand() works. In particular, rand returns