Message-ID: <343A8B8D.4EA07EA2@provider.com.br> Date: Tue, 07 Oct 1997 16:20:45 -0300 From: Antonio Dias MIME-Version: 1.0 To: djgpp AT delorie DOT com Subject: Random numbers again... Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Precedence: bulk Hi all, I was looking all that messages about random numbers and I decided to investigate. I discover that to generate a true random number you must use ramdom() function instead of rand(). These functions need to be initialized with a seed to work well. This is acomplished using srandom() function. The srandom() function expects a int as seed and if your program always send the same seed it will *always* get the same ramdom numbers. The problem now consists in pass a new seed to srandom everytime you start your program. I acomplish this using the hundreds of seconds from machine's internal clock. Look the code below: /******************** * * Generating ramdom numbers. * */ #include // for printf() #include // for random() and sramdom() #include // for gettime() int main(void) { int r; struct time t; gettime(&t); srandom((int) t.ti_hund); for(int i = 1; i < 10; i++) { r = random(); printf("Random number -> %i\n"); } } /* eof */ I'm very new in c/c++ programming, so excuse-me about any mistake. Sorry about my bad english too! Huge Hugs, Antonio Dias --- BIOS problem: Begginner Insane Operating System