I would like to generate a random number between 0 and 3 and I have the following in my code:
int random = rand() % 4;
This works fine but
Just code exactly what you want:
int myrand(void) { const int percentZero = 10; if ((rand()%100) < percentZero) return 0; return 1 + (rand() % 3); }
You can change the percentage of time zero is returned to whatever you want.