C++ Logo

std-proposals

Advanced search

Re: [std-proposals] solution proposal for Issue 2524: generate_canonical can occasionally return 1.0

From: Henry Miller <hank_at_[hidden]>
Date: Sun, 07 Dec 2025 14:13:10 -0600
>
> If we need to break implementations by changing standard, could the
> standard at least require exact same results on every implementation?
> Like in multiplayer video games whole simulation is run indepedly on
> every machine and each one need to use diffrent compiler (like android
> phone have Clang, Linux use GCC and Windows use MSVC).
> If each implementation have freedom to use any algorithm as long it
> preserve probability then game will desync players with code from
> other compilers.
>
> Of course this will have drawbacks as sometimes some enforced
> algorithms will not be perfect and can't be updated if they have bugs.
> Maybe we should have some group of algorithms that guarantee the same
> results on all implementations?
>

SG14 has more than once asked for someone to figure this out - it is known that the current state is not ideal for games, (and likely not for other major users of C++), but someone needs to put in the work to write the papers on what more algorithms C++ should have.

I think the correct answer is there should be a simple as possible way to get a random number, but the exact method is implementation defined - more of less the case today. For students and other non-critical things this is good enough. (though if we can make it simpler that is potentially good)

However there are many cases you care more and there the current random doesn't provide enough options. Which options/algorithms we should have in c++ is open for debate - random numbers have long been a favorite subject of PHD thesis for good reason, so anyone writing a paper needs to have a lot of knowledge of the space and who uses them in the real world: to find a good but manageable set of algorithms to propose we add, and justify why those are good choices. Probably the first step is a paper an who uses random numbers in C++ and how satisfied they are with the current state - more important what about the current state is not satisfactory to each group. That paper will then guide the next papers that add the needed changes, hopefully giving guidelines to everyone interested so they can write papers that complement each instead of conflicting.

Received on 2025-12-07 20:13:36