diff options
Diffstat (limited to 'standard.c')
-rw-r--r-- | standard.c | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -135,6 +135,44 @@ int flerp(int a, int b, int t) { return a + ((t * (b - a)) >> fbits); } +void vec_nrmise(int* x, int* y) { + int l; + + l = ((*x * *x) >> fbits) + ((*y * *y) >> fbits); + *x = (*x << fbits) / l; + *y = (*y << fbits) / l; +} + +static unsigned rng_seed, n; + +void seed_rng(unsigned seed) { + rng_seed = seed; + n = seed; +} + +unsigned get_seed() { + return rng_seed; +} + +unsigned rng() { + int a; + unsigned r; + + n++; + + a = n * 15485863; + r = (a * a * a % 2038074743); + return r; +} + +int rand_range(int a, int b) { + return a + (int)(rng() % ((unsigned)(b - a) + 1)); +} + +int randf() { + return (int)(rng() % ((1 << fbits) + 1)); +} + int int_to_buf(int n, char* buf) { int i, sign, t; unsigned n1; |