misshyde misshyde - 21 days ago 8
C Question

Random odd numbers between range with the exception of a single number in C

Here is my code:

alpha = ((rand() % 12) + 1) * 2 + 1;


I want to generate random odd numbers between 0-25. But except integer 13. How can I fix this? Thank you.

Answer

Generates number from 0 to 23. If it's a 13, then store 25 in your variable :

alpha = ((rand() % 11) + 1) * 2 + 1;
if (alpha == 13) alpha = 25;