www.delorie.com/archives/browse.cgi | search |
From: | jlouwere AT galaxy DOT csc DOT calpoly DOT edu (Jan Louwerens) |
Newsgroups: | comp.os.msdos.djgpp |
Subject: | Re: random numbers error in DJGPP |
Date: | 4 Feb 1997 04:23:35 GMT |
Organization: | Cal Poly Computer Science Dept. |
Lines: | 26 |
Message-ID: | <5d6dk7$b2o@waldorf.csc.calpoly.edu> |
References: | <32F44A89 DOT 3142 AT ix DOT netcom DOT com> |
NNTP-Posting-Host: | galaxy.csc.calpoly.edu |
To: | djgpp AT delorie DOT com |
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
Terence Ramos (de-bug AT ix DOT netcom DOT com) wrote: : Hello... : I have been having trouble to get DJGPP to give me random numbers. I am : using the function rand()... this is how my source looks like : number = rand() % 100 + 1; : that should give me a random number from 1 to 100 right? well i keep on : getting the same number which is 1. So i took out the + 1 part and now : i only get 0. whats wrong here? Any help would be appreciated... Make sure you include the stdlib.h header file: #include <stdlib.h> // for rand() and srandom(int seed) Also, you should seed the random number generator so that your values are different every time you run the program: #include <time.h> srandom(time(NULL)); --- JL
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |