Skip to content

Instantly share code, notes, and snippets.

@simonlc
Created March 30, 2018 03:49
Show Gist options
  • Save simonlc/633c0a7e4fc7db7af06ea869b43f1ddb to your computer and use it in GitHub Desktop.
Save simonlc/633c0a7e4fc7db7af06ea869b43f1ddb to your computer and use it in GitHub Desktop.
#include <webassembly.h>
struct rng_state {
unsigned int seed;
};
export unsigned short type0_rand(struct rng_state *r) {
unsigned int t;
t = 0x41C64E6DUL * r->seed + 12345;
r->seed = t;
return (t >> 10) & 0x7FFF;
}
void export set_seed(struct rng_state *r, unsigned int seed) {
r->seed = seed;
}
int * export create_randomizer() {
struct rng_state r;
struct rng_state *r1 = &r;
return &r1;
}
int main(void) {
int i, ranvals[5];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment