int a;
srand(time(NULL)); //bunu kullanmazsan rand sürekli aynı sayıları döndürür.
a=rand();
time() fonksiyonu için "time.h"'ı ve srand() fonksiyonu için "stdlib.h"'i include etmen gerekir.
örneğin burada senin sorunun tam tersi bir durum var buna bakarak çözebilirsin olayı. Burada sayıyı sen tahmin etmeye çalışıyorsun.
/* rand example: guess the number */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main ()
{
int iSecret, iGuess;
/* initialize random seed: */
srand ( time(NULL) );
/* generate secret number: */
iSecret = rand() % 10 + 1;
do {
printf ("Guess the number (1 to 10): ");
scanf ("%d",&iGuess);
if (iSecret<iGuess) puts ("The secret number is lower");
else if (iSecret>iGuess) puts ("The secret number is higher");
} while (iSecret!=iGuess);
puts ("Congratulations!");
return 0;
}
www.cplusplus.com