3 ms·
Random number generator (included) by language
- Bostonian 5y ago"State the type of random number generator algorithm used in a language's built-in random number generator. If the language or its immediate libraries don't provide a random number generator, skip this task. If possible, give a link to a wider explanation of the algorithm used." Fortran has multiple compilers, and the standard does not prescribe the algorithm for RNG to be used. I imagine the situation is similar for C and C++.
- Someone 5y agoI 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)