From Jason Turner
Watch on YouTube

Summary

This episode demonstrates how to implement a compile-time random number generator using constexpr in C++. Jason presents a pseudorandom number generator (PCG) that can generate sequences of deterministic but seemingly random numbers entirely at compile time. He explains how to create a constexpr-enabled version of the generator and then extends it to produce different random sequences on each compilation by seeding it with the __TIME__ macro. This technique allows developers to bake random values into their programs at compile time, potentially useful for applications like procedurally generated game content, where having the randomness pre-calculated can improve runtime performance.

Resources

Tags