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

From: gfoot AT mc31 DOT merton DOT ox DOT ac DOT uk (George Foot)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: DJGPP random numbers
Date: 5 Mar 1997 09:14:56 GMT
Organization: Oxford University
Lines: 34
Message-ID: <5fjdig$9hv@news.ox.ac.uk>
References: <5f5nr3$8js AT news00 DOT btx DOT dtag DOT de> <857552161 DOT 340179 AT red DOT parallax DOT co DOT uk>
NNTP-Posting-Host: mc31.merton.ox.ac.uk
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

John Eccleston (johne AT parallax DOT co DOT uk) wrote:
: 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?

: 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

[code snipped]

This is portable, yes, but the random() function returns numbers which
are `more random' than rand()'s, whichever parts of the number you use. 
It isn't portable, though.

To get a number from 0 to 255 using it you could do random()%256, or 
random()&0xff which is equivalent.

To seed random(), you put srandom(seed); similar to using srand() to seed
rand().

-- 
George Foot <gfoot AT mc31 DOT merton DOT ox DOT ac DOT uk>
Merton College, Oxford.

- Raw text -


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