delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/05/05:04:03

From: johne AT parallax DOT co DOT uk (John Eccleston)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: DJGPP random numbers
Date: Wed, 05 Mar 97 08:55:48 GMT
Organization: Parallax Solutions Ltd
Message-ID: <857552161.340179@red.parallax.co.uk>
References: <5f5nr3$8js AT news00 DOT btx DOT dtag DOT de>
NNTP-Posting-Host: red.parallax.co.uk
Cache-Post-Path: red.parallax.co.uk!unknown AT parsnip DOT parallax DOT co DOT uk
Lines: 61
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Gunnar wrote:
>Hi!
>
>Sorry for asking that stupid question, but can anybody tell me how i can
>get random numbers from 0 to 255?
>
>Do i have to call something like a randomize timer function like in
>Borland?
>
>---
>Gunnar Beushausen
>GBeushausen AT t-online DOT de
>http://www.hof.de/~gbasic

Hi Gunnar,

To get random numbers try the following sample, it uses standard
C libraries so should be portable as well.

Mit freundlichen gruessen

John

-----> CUT HERE <-----
#include <time.h>
#include <stdlib.h>
#include <stdio.h>

main()
{
   int
      random,
      loop;

   /*
    * Randomise the seed used for random numbers
    * the easiest way to do this is from the system clock
    */
   srand(time(NULL));

   for(loop = 0; loop < 20; loop++)
   {
      /* Get the random number */
      random = rand() % 256;

      printf("Random number %2d: %d\n", loop, random);
   }
}
-----> CUT HERE <-----

________________________________________________________________
Parallax Solutions Ltd.   Tel.: 01203 514522
Stonecourt,               Fax.: 01203 514401
Siskin Drive,             Web : http://www.parallax.co.uk/~johne
Coventry CV3 4FJ          Mail: johne AT parallax DOT co DOT uk
________________________________________________________________
                         Remember:
 There is no such thing as computer error, it's 100% YOUR fault
________________________________________________________________


- Raw text -


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