Mail Archives: djgpp/1997/03/05/05:37:38
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 -