Skip to content

Instantly share code, notes, and snippets.

@Lakhan-Nad
Last active August 2, 2020 11:33
Show Gist options
  • Save Lakhan-Nad/03fd6d2e15cbcff7190ae2fa8bf0e2fb to your computer and use it in GitHub Desktop.
Save Lakhan-Nad/03fd6d2e15cbcff7190ae2fa8bf0e2fb to your computer and use it in GitHub Desktop.
linear congruential generator implemented in CPP
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