Browse code

Seed with time in seconds since the epoch

Robert Cranston authored on 21/05/2025 01:04:11
Showing 2 changed files

... ...
@@ -8,7 +8,7 @@ Features:
8 8
 -   Algorithms
9 9
     -   Hunt And Kill
10 10
         -   Handles mazes of any size
11
-        -   Random with seed
11
+        -   Random with seed (time in seconds since the epoch by default)
12 12
         -   Fairly naive
13 13
 
14 14
 [`cxx-maze`]: https://git.rcrnstn.net/rcrnstn/cxx-maze
... ...
@@ -1,4 +1,5 @@
1 1
 #include <cstdlib>
2
+#include <ctime>
2 3
 #include <iostream>
3 4
 #include <vector>
4 5
 
... ...
@@ -99,7 +100,7 @@ Maze hunt_and_kill(int w, int h, unsigned seed)
99 100
 
100 101
 int main()
101 102
 {
102
-    auto seed = 0;
103
+    auto seed = (unsigned)std::time(nullptr);
103 104
     auto maze = hunt_and_kill(80/2, 24-1, seed);
104 105
     maze.print();
105 106
 }