æµ·é£Ž wrote:

How to generate a random integer that is bigger than RAND_MAX.

the RAND_MAX is the max of rand function. and equal to 0x7fff

You could write your own generator which can easily be at least as good

as the one provided by your standard library. "Numerical Recipes in

C++" (or any other language) has a pretty good treatment of this. In

particular, you can start with a seed and iterate, using

X_{n+1} = a * X_n + c (mod 2^32),

for sufficient choices of a and c (evidently, a=1664525 and

c=1013904223 work well). If your integers are 32-bit, then the mod

happens automatically when you multiply and they overflow (and even if

they are longer than 32 bits, you can mask out the higher bits). Thus,

a quick and dirty function would be

unsigned int random() {

static unsigned int x;

x = 1664525L * x + 1013904223L;

return x;

}

-steve