Category : random

void generate_number(){ srand(time(0)); int generated_number = rand()%101; }; so i’ve created a function just to create numbers whenever i’d want to.But the variable is non-reachable from other functions and there is probably another problem either bcs i’ve created it as "int generated_number = …" i’d like to use this "generated number". But im confused. lets ..

Read more

In https://lemire.me/blog/2019/06/06/nearly-divisionless-random-integer-generation-on-various-systems/, Lemire uses -s % s to compute something which according to the paper is supposed to be 2^L % s. According to https://shufflesharding.com/posts/dissecting-lemire this should be equivalent, but I’m getting different results. A 32-bit example: #include <iostream> int main() { uint64_t s = 1440000000; uint64_t k1 = (1ULL << 32ULL) % s; uint64_t ..

Read more

BEGGING: PLEASE DO NOT close my question, I couldn’t find any solution from duplicating questions and answer. I asked this question 3 times and looking forward your suggestions. Please. PROBLEM: In my program, rand() is called twice, and on last call, the return value is always same. The first call with srand(), returns different value, ..

Read more

I’ve often heard that you should never mod the result of your random number generator if you want a uniform distribution. However, I’ve seen that using a std::uniform_int_distribution makes no difference for significantly small ranges. Below is an example using both mod and uniform_int_distribution for values 0 – 15: std::mt19937 gen; gen.seed(0); int ROWS = ..

Read more

I have: std::random_device rd; std::mt19937 mt(rd()); std::uniform_int_distribution<int> probability(0, 100); I want to exclude some numbers in this range of probabilities. Example1: Let’s say, I want to generate a random number in between 0 and 100, but this number can never be 4. Example2: Let’s say, I want to generate a random number in between 0 ..

Read more