aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2024-10-02 20:14:19 +1000
committerquou <quou@disroot.org>2024-10-02 20:14:19 +1000
commitf430e6080afd75a0c0aecdb0a0223f0f3b23b993 (patch)
tree35bb37149e154708097fda34824d5858a6136812
parent4d94823a1523db6dc218bdc0d86689616c13599d (diff)
random
-rw-r--r--Makefile1
-rw-r--r--random.c59
-rw-r--r--random.h13
3 files changed, 73 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 3f107ed..06f7573 100644
--- a/Makefile
+++ b/Makefile
@@ -56,6 +56,7 @@ sources = \
physics.c \
plat.c \
player.c \
+ random.c \
rect.c \
render.c \
world.c \
diff --git a/random.c b/random.c
new file mode 100644
index 0000000..7220bc8
--- /dev/null
+++ b/random.c
@@ -0,0 +1,59 @@
+#include "random.h"
+
+int random_table[] = {
+ 0x67fd, 0xa400, 0xcc83, 0x1b3d, 0xf532, 0x2557,
+ 0x6667, 0x2948, 0x9965, 0xfec0, 0xf7ee, 0x2d4a,
+ 0x03b4, 0x1a45, 0x5d5d, 0xe673, 0x048c, 0xd045,
+ 0xfa5d, 0x8375, 0xbf62, 0xa50f, 0x9e98, 0x7b95,
+ 0x8ff1, 0x0fdf, 0x993a, 0xb5a5, 0xe173, 0xa2dc,
+ 0x23da, 0xd338, 0x5b47, 0xe017, 0xd2c4, 0x1aab,
+ 0x254b, 0xbd41, 0x15d1, 0x4906, 0x174f, 0xc84a,
+ 0x42d4, 0x679d, 0xe316, 0xd310, 0xdfb1, 0x4bb5,
+ 0x149d, 0x8641, 0x25e3, 0x2f6a, 0x3637, 0x6c14,
+ 0x019f, 0x2b75, 0xa176, 0x826a, 0xff9a, 0x6855,
+ 0x70e6, 0x42fe, 0xbaf1, 0xa8c1, 0x7e3d, 0x4c76,
+ 0x2278, 0xd0a1, 0x60b8, 0x363e, 0x71ee, 0x5006,
+ 0x2c5f, 0x26b3, 0x99b9, 0x98e6, 0xfc85, 0x9ddf,
+ 0xe690, 0x93fb, 0x6301, 0x9138, 0xcbb8, 0x0ff8,
+ 0x7618, 0xa9d3, 0x5629, 0x1f7f, 0xb5e0, 0x27a9,
+ 0x8bbc, 0x8744, 0xb871, 0x2600, 0x2f54, 0xb256,
+ 0xac94, 0x575e, 0x57f2, 0xe03f, 0x6468, 0x2159,
+ 0x0272, 0x4fb7, 0x156e, 0x6dfe, 0xd964, 0xd311,
+ 0xbeb7, 0xf05c, 0x2996, 0x8af0, 0x98ea, 0xf006,
+ 0x1536, 0x4ded, 0x36b9, 0x1759, 0xf016, 0x17a2,
+ 0x6061, 0x020c, 0xa432, 0xdfe5, 0xdb33, 0x6efb,
+ 0x26c2, 0x56ed, 0xdbcf, 0xe3c2, 0x5c55, 0x2f10,
+ 0x813b, 0x14fc, 0x96d5, 0x6a7c, 0xa6f1, 0x4357,
+ 0x37aa, 0x1c41, 0xc89f, 0x43b5, 0xb126, 0x9d78,
+ 0x02ef, 0x8193, 0x3b4b, 0x2bb0, 0x9d00, 0x53c1,
+ 0x4fda, 0x6caf, 0xfe95, 0x3006, 0x70a3, 0xc343,
+ 0x9a01, 0xd4fb, 0x3342, 0x9ed6, 0xead8, 0xfc92,
+ 0xd061, 0x5922, 0x93a1, 0xfb5e, 0x5131, 0x5f7d,
+ 0x8d3a, 0xcc79, 0xeed3, 0x1165, 0x014d, 0xfd71,
+ 0x528f, 0x6d22, 0xe6f3, 0x96ff, 0xddc4, 0x298c,
+ 0xe0af, 0xe74c, 0x0982, 0x0f90, 0x7ddd, 0x18ef,
+ 0xce80, 0x6e73, 0x4af1, 0x9cf0, 0xbc5c, 0x82c9,
+ 0x58cc, 0xddc9, 0x40a4, 0x98b1, 0x6547, 0x19d3,
+ 0xfc50, 0xfa4c, 0x46db, 0x8796, 0x5f75, 0xb92e,
+ 0x7919, 0xdfeb, 0xa5b1, 0xcfd3, 0xbcf0, 0xcc0e,
+ 0x520f, 0x9b3d, 0x6a24, 0x418a, 0xd63b, 0x9fee,
+ 0x6ebb, 0x93ab, 0xab35, 0xe958, 0xae91, 0xed8c,
+ 0x6d36, 0x893b, 0x7a06, 0xd7e1, 0x9b5d, 0xae1a,
+ 0xa868, 0xe28a, 0xbe3d, 0xe238, 0xa72c, 0xf238,
+ 0xca65, 0x4dd5, 0xe843, 0xd36c, 0xb169, 0xe8e7,
+ 0x31e5, 0x100f, 0x28b0, 0x75b5, 0x8d0f, 0x169a,
+ 0x6462, 0x861f, 0xe89e, 0x579f, 0x50bf, 0x42ea,
+ 0x1a60, 0x4bce, 0x6ccb, 0x1cfe
+};
+static int index = 0;
+
+int get_r(void) {
+ index = (index + 1) & random_table_mask;
+ return random_table[index];
+}
+
+int get_rrange(int mi, int ma) {
+ int n = get_r();
+ int r = ma - mi + 1;
+ return n % r + mi;
+}
diff --git a/random.h b/random.h
new file mode 100644
index 0000000..22375a1
--- /dev/null
+++ b/random.h
@@ -0,0 +1,13 @@
+#ifndef random_h
+#define random_h
+
+#define random_table_count 0x100
+#define random_table_mask 0x0ff
+#define random_max 65535
+
+extern int random_table[random_table_count];
+
+int get_r(void);
+int get_rrange(int mi, int ma);
+
+#endif