*Source - BIX borland/turboc conference msg #4123, drifkind, 7/13/90*

Problem:
random(n) occasionally returns n when it should be limited to return
value range 0...n-1.

Explanation:

RAND_MAX is defined to be 0x7fff, the maximum value that rand() returns.
random() definition shoule use ((long)RAND_MAX+1) instead of RAND_MAX
for divisor to assure range of 0...n-1 for return.

Fix:

Change definitions in stdlib.h as follows:

original definitions -

...
inline int	_Cdecl random(int __num) { return (int)(((long)rand()*__num)/RAND_MAX); }
...
#define random(num)	(int)(((long)rand()*(num))/RAND_MAX)
...

change to -

...
inline int	_Cdecl random(int __num) { return (int)(((long)rand()*__num)/((long)RAND_MAX+1)); }
...
#define random(num)	(int)(((long)rand()*(num))/((long)RAND_MAX+1))
...
