Turbo C (DOS): what does randomize() do? Legacy compiler question about seeding the pseudo-random generator.

Difficulty: Easy

Correct Answer: returns a random number generator with a random value based on time.

Explanation:


Introduction / Context:
This question refers to Borland/Turbo C for DOS, which provides non-standard functions such as randomize() and random(). Understanding legacy behavior is useful when reading old codebases or porting programs.


Given Data / Assumptions:

  • Environment: Turbo C (non-ISO, DOS era).
  • randomize() is available along with random() or rand().


Concept / Approach:

In Turbo C, randomize() initializes (seeds) the pseudo-random number generator using a semi-random value, commonly derived from the system clock. It does not return a random number; rather, it prepares subsequent calls to random()/rand() to yield different sequences between runs.


Step-by-Step Solution:

1) Call randomize() once near program start. 2) Call random(N) or rand() to obtain pseudo-random values. 3) Observe that sequences differ each run because the seed varies with time.


Verification / Alternative check:

Without randomize(), consecutive runs produce the same sequence (deterministic seed). With it, the seed changes and so do the outputs.


Why Other Options Are Wrong:

returns a random number: That describes random() or rand(), not randomize().

returns a random number generator in the specified range: Confuses generation with seeding and range restriction.

return a random number with a given seed value: Seed is set, not returned; and randomize() does not take an explicit seed.


Common Pitfalls:

  • Assuming Turbo C functions are part of ISO C—portability issues arise.
  • Expecting randomize() to produce a number directly.


Final Answer:

returns a random number generator with a random value based on time.

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion