codice:
#include <iostream> 
#include <cstdlib> 
#include <ctime>
using namespace std; 

int main() 
{ 
int magic; // numero magico 
int guess; // tentativo del giocatore 

srand(time(0));//seleziona il seme

magic = rand();
//così è troppo difficile trovare il numero, puoi fare fra 1 e 100 
//così:
//magic = 1 + rand() % 100;


do { 
cout << "Scrivi il tuo numero: "; 
cin >> guess; 
if(guess == magic) { 
cout << "** Giusto ** "; 
cout << magic << " è il numero magico.\n"; 
} 
else { 
cout << "...Mi dispiace, hai sbagliato."; 
if(guess > magic) 
cout << " Il tuo numero è troppo alto.\n"; 
else cout << " Il tuo numero è troppo basso.\n"; 
} 
} while(guess != magic); 

return 0; 
}
Con srand crei un seme per generare numeri casuali, se vuoi creare un numero fra x e y devi fare:

rand = x + rand() % y