aboutsummaryrefslogtreecommitdiff
path: root/standard.c
diff options
context:
space:
mode:
Diffstat (limited to 'standard.c')
-rw-r--r--standard.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/standard.c b/standard.c
index 801777c..5e464f6 100644
--- a/standard.c
+++ b/standard.c
@@ -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;