#include <iostream> #include <cstdlib> using namespace std; int main() { int i; int r; r = rand(); for(i=0; r <= 20000; i++) r = rand(); cout << "Number is " << r << ". It was generated on try " << i << "."; return 0; }
Number is 26500. It was generated on try 3."