delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/01/10/21:39:57

From: jsinger AT expert DOT cc DOT purdue DOT edu (Jason Singer)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: random()
Date: 10 Jan 1997 19:23:33 GMT
Organization: Purdue University Computing Center
Lines: 36
Message-ID: <5b64vl$ldv@mozo.cc.purdue.edu>
References: <5aouvm$erv AT cocoa DOT brown DOT edu>
NNTP-Posting-Host: expert.cc.purdue.edu
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

: Is there a randomize() funtion for DJGPP?  If so
: which Lib is it in?  I keep getting the same #'s
: when I use the random() funtion, and I need
: to randomize the # seed.

I had the same problem, so I made my own.  Here's what I use:

void randomize(void)
{
   int num = (int) time(NULL);
   if (num < 0)
      num = -num;
   srandom( num );
}

// Gets a random integer from 0 to top - 1.
int getRand(int top)
{
   int num = (int) random();
   if (num < 0)
      num = -num;
   return num % top;
}

Hope that helps,

Jason

=================================
           Smile!!!!!!!
               \|/
               O O
-----ooooO----(   )----Ooooo-----
                O
And Have a Grrrrrrreat Day!!!!!!!
=================================

- Raw text -


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