https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88935
--- Comment #10 from Xi Ruoyao <xry111 at gcc dot gnu.org> --- (In reply to Jonathan Wakely from comment #9) > (In reply to Xi Ruoyao from comment #7) > > The C++11 standard explicitly allows to use rand() as the random source for > > random_shuffle, thus this is not a bug but an enhancement. > > It doesn't just allow it, it requires it. But the standard also requires a > uniform distribution, and we fail to meet that requirement because of the > range of RAND_MAX. (We actually fail to meet it on all targets, because we > use % which is not uniformly distributed unless RAND_MAX is an exact > multiple of (last - first), so we always have a bias.) I cannot see how it is possible to guarantee an uniform distribution with rand() because the C standard even says rand() is allowed to be very stupid: > There are no guarantees as to the quality of the random sequence produced > and some implementations are known to produce sequences with distressingly > non-random low-order bits. Applications with particular requirements should > use a generator that is known to be sufficient for their needs.