Many examples of
std::generate in C++ involve a static. However using a static introduces issues around thread safety and usability in modern code. Here is a simple example using
std::generate with a c++14 style lambda that defines and captures a local variable.
Full tutorial on YouTube: