Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdint.h>
- #include <stdlib.h>
- struct RandomGenerator;
- typedef struct Operations
- {
- void (*destroy)(struct RandomGenerator*);
- int (*next)(struct RandomGenerator*);
- } Operations;
- typedef struct RandomGenerator
- {
- int current;
- int a;
- int c;
- int mod;
- Operations* ops;
- } RandomGenerator;
- void destroy(RandomGenerator *gen) {
- free(gen);
- }
- int next(RandomGenerator *gen) {
- return gen->current = (((__int64_t) gen->a * gen->current + gen->c) & gen->mod);
- }
- Operations operations = {destroy, next};
- RandomGenerator *random_create(int seed) {
- RandomGenerator* gen = malloc(sizeof(RandomGenerator));
- gen->current = seed;
- gen->a = 1103515245;
- gen->c = 12345;
- gen->mod = (1LL << 31) - 1;
- gen->ops = &operations;
- return gen;
- }
- int main() {
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement