An alternative approach uses an array with all valid values, and generates a random index for the array. It will guarantee always a valid value in the first try.
The price is the array takes memory, in your case 62 bytes.
simplified example, random prime below 100, there would be 75 values to skip (75% chance).
int number;
const int NRVAL = 25;
uint8_t validValues[NRVAL] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 };
void setup()
{
Serial.begin(115200);
randomSeed(analogRead(0));
}
void loop()
{
number = validValues[random(NRVAL)];
Serial.println(number);
delay(1000);
}