"The rand function returns a pseudorandom integer in the range 0 to RAND_MAX (32767). " so it returns 0 thru 32766, but not 32767, right?

Correct. In modern math notation this type of function works with [0,x) meaning it includes zero but stops just short of x. This is also common in many other systems. Graphics, for example, typically draw segments in the [A,B) form, starting exactly at A and ending the instant before B.

I tried this in VS2015 and it does return RAND_MAX.. is it not supposed to?

#include <iostream> int main() { for(int i = 0; i < 200000; ++i) { int r = rand(); if(r == RAND_MAX) std::cout << "MAX\n"; else if(r == (RAND_MAX - 1)) std::cout << "ALMOST\n"; else if(r == 0) std::cout << "ZERO\n"; } }

The range for both *rand()* and the *<random>* library (at least the uniform integer distributions when comparing with *rand*) are inclusive at both ends. The range is therefore [0, RAND_MAX], not [0, RAND_MAX). This is different from, for example, iterator ranges in the standard library which are half-open.