Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<random> Pick a different backing random number engine for default_random_engine #4257

Open
horenmar opened this issue Dec 12, 2023 · 4 comments
Labels
decision needed We need to choose something before working on this vNext Breaks binary compatibility

Comments

@horenmar
Copy link
Contributor

Currently it is alias for mt19937. mt19937 is not a bad generator on its own, but it is not a good default. The reason is that MTs are excessively large, so sizeof(default_random_engine) == 5000 right now. This is much larger than the user would reasonably expect, for comparison, xoshiro fits into 16-32 bytes, PCG usually fits into 8-16, common LCGs will be 8. WELLs can be as large as MTs, but there are also reasonably sized variants at 32 bytes.

The choice of default_random_engine also has knock-on effects beyond just the direct users, e.g. the simple random utilities wanted to use a thread-local instance of default_random_engine, but that means shoving 5k objects into the TLS. As I understand it, there is nothing really blocking that, but it is not great.

@horenmar horenmar added the question Further information is requested label Dec 12, 2023
@fsb4000
Copy link
Contributor

fsb4000 commented Dec 13, 2023

Thank you for your suggestion! It seems reasonable, but it would require an ABI-breaking change. We can consider implementing it in the vNext version (not Visual Studio 2022).

vNext note: Resolving this issue will require breaking binary compatibility. We won't be able to accept pull requests for this issue until the vNext branch is available. See #169 for more information.

@fsb4000
Copy link
Contributor

fsb4000 commented Dec 13, 2023

изображение

@horenmar
Copy link
Contributor Author

Yeah I know, I talked with STL somewhere and he said to open an issue so it might happen in vNext.

@CaseyCarter CaseyCarter added vNext Breaks binary compatibility decision needed We need to choose something before working on this and removed question Further information is requested labels Dec 13, 2023
@StephanTLavavej
Copy link
Member

LCGs are garbage but if there were a better option than mt19937[_64] then we should consider it for vNext. There appears to be nothing technically preventing default_random_engine from being a choice outside the Standard set, so it could be an implementation of PCG or some other algorithm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
decision needed We need to choose something before working on this vNext Breaks binary compatibility
Projects
None yet
Development

No branches or pull requests

4 participants