Examveda

Which of the following code will generate unique random numbers every time?

A.

#include <stdlib.h> 
int main() 
{ 
     srand(0); 
     printf("%d\n", rand()%50); 
     return 0; 
}

B.

#include <stdlib.h> 
int main() 
{ 
     srand(time(0)); 
     printf("%d\n", rand()%50); 
     return 0; 
}

C.

#include <stdlib.h> 
int main() 
{ 
    srand(1); 
    printf("%d\n", rand()%50); 
    return 0; 
}

D.

#include <stdlib.h> 
int main() 
{
     printf("%d\n", rand()%50); 
     return 0; 
}

Answer: Option B


This Question Belongs to Data Structure >> Miscellaneous On Data Structures

Join The Discussion

Related Questions on Miscellaneous on Data Structures