+ 1
Random number in c
Will the generated random number have different value when i run it again and again? #include <stdio.h> #include <stdlib.h> int main() { unsigned short int random =88; int i; for(i=0;;i++) { random = rand(); printf("The random number generated %d\n",random); if(random <= 100 && random >=1) { printf("Random number is between 1 to 100\n"); break; } } printf("Random no: %d",random); return 0; } in the above case?
4 Réponses
+ 4
No, you need to modify the seed. The common way to use it is srand(time(0)), don't forget to include time header file. Btw, what's that 88 for?
+ 2
Okay thank you..😄
+ 1
I wrote 88 because I thought that variable might take a garbage value if not initialized(as it is a local variable) ..so I wouldn't know weather the value in it is garbage value or a random number .. and thanq for the answer
+ 1
Srujan Landeri It won't take a garbage value since you replaced it with rand().