summaryrefslogtreecommitdiffstats
path: root/src/rand.rs
diff options
context:
space:
mode:
authorRose Hogenson <rosehogenson@posteo.net>2024-01-14 16:01:32 -0800
committerRose Hogenson <rosehogenson@posteo.net>2024-01-14 16:01:32 -0800
commit680fdffb350b2409ac1709774d3cd81144d808a4 (patch)
treeea9b7c2a321a89a2919bbbf1d7012a9e97f73c58 /src/rand.rs
downloadsnake-680fdffb350b2409ac1709774d3cd81144d808a4.tar.zst
Write a simple snake game.
Diffstat (limited to 'src/rand.rs')
-rw-r--r--src/rand.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/rand.rs b/src/rand.rs
new file mode 100644
index 0000000..f9aee46
--- /dev/null
+++ b/src/rand.rs
@@ -0,0 +1,17 @@
+pub struct Gen {
+ state: i64,
+}
+
+
+pub fn new(seed: i64) -> Gen {
+ Gen{
+ state: seed,
+ }
+}
+
+impl Gen {
+ pub fn rand(&mut self, max: i32) -> i32 {
+ self.state = self.state.wrapping_mul(6364136223846793005).wrapping_add(1);
+ (self.state >> 33 & 0x7fffffff) as i32 % max
+ }
+}