Last active
August 2, 2020 11:33
-
-
Save Lakhan-Nad/03fd6d2e15cbcff7190ae2fa8bf0e2fb to your computer and use it in GitHub Desktop.
linear congruential generator implemented in CPP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class random { | |
private: | |
static long long seed; | |
static const long long rand_max = 4294967296; // 2^32 | |
static const long long multiplier = 22695477; | |
static const long long increament = 1; | |
public: | |
static void srand(long long s) { seed = s; } | |
static long long rand() { | |
seed = ((seed * multiplier) + increament) % rand_max; | |
return seed; | |
} | |
}; | |
/* Initializing Static Variable */ | |
long long random::seed = 4321; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment