www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/01/28/20:18:00

From: myknees AT aol DOT com (Myknees)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Random implementation
Date: 29 Jan 1998 00:39:44 GMT
Lines: 28
Message-ID: <19980129003900.TAA29842@ladder03.news.aol.com>
NNTP-Posting-Host: ladder03.news.aol.com
References: <34CEAEE2 DOT 2DCF AT cs DOT com>
Organization: AOL http://www.aol.com
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

I have tried to do random numbers before without success.  Now I think I know
why.  In the info documentation's alphabetical list, there is no mention of
srand().  And there's no cross reference to srand() from rand().

I was able to glean from this thread that you're supposed to do something like
this:
#include        <stdio.h>
#include        <stdlib.h>
#include        <time.h>
#include        <bios.h>

int main(void)
{
    char c;
    
    while((c=bioskey(0))!='x'){
      printf("%-10c", c);
      srand(time(0));
      printf("And the random number is...   %d\n", rand());
    }
        
    return 0;
}

But if this is right, how would a beginner find it out?  (Besides, of course,
reading about it from an outside source.)

--Ed (Myknees)

- Raw text -


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