Q:

How computationally expensive is generating a random number in C++?

The method that I am considering is from: https://stackoverflow.com/a/19728404/6571958
#include <random>

std::random_device rd;     // only used once to initialise (seed) engine
std::mt19937 rng(rd());    // random-number engine used (Mersenne-Twister in this case)
std::uniform_int_distribution<int> uni(min,max); // guaranteed unbiased

auto random_integer = uni(rng);

I'm also willing to use the rand() approach with srand(time(NULL)).
My question: how expensive are these approaches? Is one much faster than the other?

A:

Performance depends greatly on the generator you use (which in turn depends greatly on the quality of the numbers you need).
For example, std::mt19937 is much faster than std::random_device but produces pseudo random numbers.
This is fine for most purposes, if you don't need cryptographically safe random numbers. But even if you do, random_device can produce raw entropy at a rate of about 50MB/sec on my machine - how much randomness do you really need? (mt19937 generates about orders of magnitudes more than that if needed).
Avoid rand(). It just has very poor properties and a very low period.
See also https://channel9.msdn.com/Events/GoingNative/2013/rand-Considered-Harmful

