59.5k views
1 vote
Type a statement using srand() to seed random:

A) srand(0)
B) srand(seed)
C) srand(time(NULL))
D) srand(randomSeed)

User Debdeep
by
8.6k points

1 Answer

3 votes

Final answer:

The correct option for seeding a random number generator with a unique value each time the program runs is C) srand(time(NULL)). Options A and B are incorrect, and Option D requires a predefined 'randomSeed' variable.

Step-by-step explanation:

The student has asked to type a statement using srand() to seed random. The correct statement to seed the random number generator used in many programming languages, like C++, is C) srand(time(NULL)). This statement initializes the random number generator with the current time, ensuring that the sequence of numbers is different on each program run. Option A seeds the generator with a constant, leading to the same sequence of numbers each time the program runs, which is typically not desirable. Option B denotes a placeholder value and would require an actual 'seed' variable containing a unique value. Option D is also a placeholder that suggests the existence of a variable named 'randomSeed' intended to hold the seed value.

User James Hancock
by
8.0k points
Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.