www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/06/04/09:01:56

From: kagel AT quasar DOT bloomberg DOT com
Date: Tue, 4 Jun 1996 08:52:21 -0400
Message-Id: <9606041252.AA02521@quasar.bloomberg.com >
To: halibut AT kuhub DOT cc DOT ukans DOT edu
Cc: djgpp AT delorie DOT com
In-Reply-To: <1996Jun3.061709.120699@kuhub.cc.ukans.edu> (halibut@kuhub.cc.ukans.edu)
Subject: Re: use of srand with djgpp?
Reply-To: kagel AT dg1 DOT bloomberg DOT com

   From: halibut AT kuhub DOT cc DOT ukans DOT edu
   Date: 3 Jun 96 06:17:09 CDT

   You'll have to forgive me if this question is too easy I'm a C
   beginner, but any it has to do with srand.

   To seed the random number table I always used srand(time(NULL)).
   I have both time.h and stdlib.h included. Djgpp refuses to accept
   this line of code. Is there any other way to do this?

   I download some programs hoping to find this answer but most
   of them had a randomize() function which Djgpp doesnt seem to touch
   and one of them even querried the user for the seed!

   Maybe this could be put in the faq?


The function time() returns a (time_t).  Simply cast it to an (unsigned int)
which is what srand() expects, hence:

	srand((unsigned int)time( (time_t *)NULL ));

-- 
Art S. Kagel, kagel AT quasar DOT bloomberg DOT com

A proverb is no proverb to you 'till life has illustrated it.  -- John Keats

BTW: Please no one get on my case about the cast of the NULL.  We've been over
that already.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019