git.fiddlerwoaroof.com
Browse code

seeded random generator

Greg Wiley authored on 04/05/2017 21:22:00
Showing 5 changed files
1 1
Binary files a/dual_control and b/dual_control differ
... ...
@@ -19,10 +19,17 @@
19 19
 #include "sys_unistd.h"
20 20
 #include "sys_pwd.h"
21 21
 #include "token.h"
22
+#include "system.h"
22 23
 #include "sys_fstream.h"
23 24
 
24 25
 namespace {
25
-    installer init() {
26
+    class system init_system() {
27
+        stdlib stdlib(stdlib::get());
28
+        sys_time time(sys_time::get());
29
+        class system system(stdlib, time);
30
+        return system;
31
+    }
32
+    installer init_installer() {
26 33
         fstreams fstreams(fstreams::create());
27 34
         tokens tokens(tokens::create(fstreams));
28 35
         pwd pwd(pwd::create());
... ...
@@ -39,7 +46,8 @@ namespace {
39 46
 
40 47
 int main (int argc, char *argv[])
41 48
 {
42
-    installer tool(init());
49
+    class system system(init_system());
50
+    installer tool(init_installer());
43 51
     std::string generated_token = tool.install_token();
44 52
     std::cout << generated_token << std::endl;
45 53
     return 0;
... ...
@@ -4,7 +4,7 @@
4 4
 #include "sys_time.h"
5 5
 
6 6
 namespace {
7
-    class impl : public time_ifc {
7
+    class impl : public sys_time_ifc {
8 8
         public:
9 9
             time_t time(time_t *timer) const override{
10 10
                 return ::time(timer);
... ...
@@ -12,7 +12,7 @@ namespace {
12 12
     };
13 13
 }
14 14
 
15
-const time_t &time::get() {
16
-    static time singleton(std::make_shared<impl>());
15
+const sys_time &sys_time::get() {
16
+    static sys_time singleton(std::make_shared<impl>());
17 17
     return singleton;
18 18
 }
... ...
@@ -21,7 +21,7 @@ class sys_time {
21 21
         time_t time(time_t *timer) const {
22 22
             return delegate_->time(timer);
23 23
         }
24
-   static const time_t &get();
24
+   static const sys_time &get();
25 25
 
26 26
 };
27 27
 
... ...
@@ -6,5 +6,11 @@
6 6
 system::system(const stdlib &stdlib, const sys_time &time) {
7 7
     unsigned seed = static_cast<unsigned>(time.time(nullptr));
8 8
     stdlib.srand(seed);
9
+    /* this makes it look like we're more random when the tool
10
+     * is invoked. it isn't necessary and we shouldn't be using
11
+     * rand() at all in the final version since it's kind of
12
+     * dumb.
13
+     */
14
+    stdlib.rand();
9 15
 }
10 16