2 ms·
I don’t think the C standard says much about its implementation. As far as I can tell #define RAND_MAX 32767 int rand (void){return 0;} (Edit: changed RAN
by Someone 5y ago
I don’t think the C standard says much about its implementation. As far as I can tell
#define RAND_MAX 32767
int rand (void){return 0;}
(Edit: changed RAND_MAX from zero. That can’t be zero, but I think rand is allowed to be spectacularly bad)
is a valid implementation.
In real life, implementations are a bit better. The small seed (just a single int) can’t make it much better, though.
The original version also is a LCG, so it has the nasty habit of very short cycle lengths when only looking at least significant bits.
C++ has multiple well-defined engines (https://en.cppreference.com/w/cpp/numeric/random https://en.cppreference.com/w/cpp/numeric/random)