Page MenuHomePhabricator

Change requirements on linear_congruential_engine
Needs ReviewPublic

Authored by zoecarver on Jul 20 2019, 4:12 PM.



This patch changes how linear_congruential_engine picks its randomization algorithm. It adds two restrictions, _OverflowOK and _SchrageOK. _OverflowOK means that m is a power of two so using the classic (a * x + c) % m will create a meaningless overflow. The second checks that Schrage's algorithm will produce results that are in bounds of min and max. This patch fixes 27839.

Diff Detail

Event Timeline

zoecarver created this revision.Jul 20 2019, 4:12 PM
zoecarver marked an inline comment as done.Jul 20 2019, 4:15 PM

I think it may be good to remove Schrage's algorithm altogether and file an LWG issue for the remaining edge cases. It is very slow and feels out of place in LCG. Additionally, Schrage's algorithm introduces lot's of added complexity and space for bugs.


This static_assert is redundant. Maybe I should remove it.