#include <random> //Random stuff
#include <ctime> //std::time
#include <iostream>
int rand_num(int from, int to)
{
//Static is needed to seed our prng only once
//and all function calls will share generator
static std::mt19937 rg(std::time(nullptr));
//distribution is recreated each call because function might be called with different parameters
std::uniform_int_distribution<> dis(from, to);
return dis(rg); //return result of generation
}
int main()
{
for(int i =0; i < 20; ++i)
std::cout << rand_num(1, 100) << '\n';
}
I2luY2x1ZGUgPHJhbmRvbT4gLy9SYW5kb20gc3R1ZmYKI2luY2x1ZGUgPGN0aW1lPiAvL3N0ZDo6dGltZQojaW5jbHVkZSA8aW9zdHJlYW0+CgppbnQgcmFuZF9udW0oaW50IGZyb20sIGludCB0bykKewogICAgLy9TdGF0aWMgaXMgbmVlZGVkIHRvIHNlZWQgb3VyIHBybmcgb25seSBvbmNlCiAgICAvL2FuZCBhbGwgZnVuY3Rpb24gY2FsbHMgd2lsbCBzaGFyZSBnZW5lcmF0b3IKICAgIHN0YXRpYyBzdGQ6Om10MTk5Mzcgcmcoc3RkOjp0aW1lKG51bGxwdHIpKTsKICAgIC8vZGlzdHJpYnV0aW9uIGlzIHJlY3JlYXRlZCBlYWNoIGNhbGwgYmVjYXVzZSBmdW5jdGlvbiBtaWdodCBiZSBjYWxsZWQgd2l0aCBkaWZmZXJlbnQgcGFyYW1ldGVycwogICAgc3RkOjp1bmlmb3JtX2ludF9kaXN0cmlidXRpb248PiBkaXMoZnJvbSwgIHRvKTsKICAgIHJldHVybiBkaXMocmcpOyAvL3JldHVybiByZXN1bHQgb2YgZ2VuZXJhdGlvbgp9CgppbnQgbWFpbigpCnsKICAgIGZvcihpbnQgaSA9MDsgaSA8IDIwOyArK2kpCiAgICAgICAgc3RkOjpjb3V0IDw8IHJhbmRfbnVtKDEsIDEwMCkgPDwgJ1xuJzsKfQ==