random number again

Started by
11 comments, last by blizzard999 18 years, 8 months ago
Darn, you are correct. In my libc (gcc 3.4), RAND_MAX was 2^31-1, and I didn't see any reason why it would be less than INT_MAX in any library - or at least, why it would be as small as 32767 with a 4-byte int.
Advertisement
Quote:Original post by Sharlin

Humm? I thought we had at least 32-bit processors and OS's these days... oh well :) Maybe some ages-old compilers might have a 16-bit int, but most? Doubtful.

Darn, you are correct. In my libc (gcc 3.4), RAND_MAX was 2^31-1, and I didn't see any reason why it would be less than INT_MAX in any library - or at least, why it would be as small as 32767 with a 4-byte int.


I'm wrong that RAND_MAX is usually 32768...in fact it is 32767 that is 2^15 - 1.
MSVC 6 is 32767, I already tested some time ago .
To be 100% sure I wrote a complex program; I show you the code

#include <iostream>#include <math.h>int main(){   std::cout << RAND_MAX << std::endl;   return 0;}


It reports 32767. This time compiled under XP with CodeBlocks/Mingw/gcc (latest version).

In stdlib.h you can read

/* * RAND_MAX is the maximum value that may be returned by rand. * The minimum is zero. */#define	RAND_MAX	0x7FFF


Why RAND_MAX is only 32767 ?

Because it sucks. [smile]

Dont use rand() if you need random numbers. The alternatives are simply and efficient.
MT main page

downloads

This topic is closed to new replies.

Advertisement