delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/06/21/13:58:32

Xref: news2.mv.net comp.os.msdos.djgpp:5246
From: DHGW39B AT prodigy DOT com (Eric Domazlicky)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: How to get a good value for srand?
Date: 21 Jun 1996 15:45:30 GMT
Organization: Prodigy Services Company 1-800-PRODIGY
Lines: 22
Distribution: world
Message-ID: <4qeg2q$327k@usenetz1.news.prodigy.com>
References: <4q9png$1u4 AT newsserv DOT grfn DOT org>
NNTP-Posting-Host: 192.168.254.73
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

>How do I get a good value for srand()???  Timer functions like 
rawclock() 
>are no good because they are always zero the first time you call them.  

>Any help?
My method is to use gettime then as you can see below take the ti_hund 
and ti_sec and combine them into one byte, it's kinda weird but it works. 
BTW the reason I have the typedef there is because DJGPP never seems to 
define the struct type that gettime is supposed to use except in the info 
file, so you have to type it yerself.

typedef struct {
unsigned char ti_min;
unsigned char ti_hour;
unsigned char ti_hund;
unsigned char ti_sec;
} time_data;

time_data t;
gettime(&t);
srand(t.ti_hund*0xff+t.ti_sec);

- Raw text -


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