4 ms·
Neat hack! One minor improvement suggestion: if you seed the RNG with `__DATE__` (or a hash of that string), then you can replicate the one-puzzle-a-day experie
by nneonneo 5y ago
Neat hack! One minor improvement suggestion: if you seed the RNG with `__DATE__` (or a hash of that string), then you can replicate the one-puzzle-a-day experience with no need for an externally-supplied seed variable.
- fathyb 5y agoWondering what happens if you allocate a chunk of uninitialized memory inside a constexpr? Could this be used for a quick constexpr RNG seed?
- xroche 5y agoYou simply can't. The constexpr environment won't let you have uninitialized variables/memory anywhere. It won't let you access dangling/out-of-bounds pointers either, overflow two-complement types, etc.
- flqn 5y agoAccessing uninitialized objects is undefined behaviour, which traps in the constexpr context.
- jcelerier 5y agoA very neat thing of constexpr is that it does not have undefined behaviour ; any thing that would cause UB at run-time is flagged as a compile error. Every variable must be fully initialized.
- SuperV1234 5y agoGood point! I wanted to be able to modify SEED in order to test that everything was fine with multiple words, using __DATE__ didn't come to mind :)
- TheSoftwareGuy 5y ago#ifndef SEED #define SEED __DATE__ #endif