瀏覽代碼

randint, randrange.

Steve Thielemann 5 年之前
父節點
當前提交
2b91ae9fc6
共有 1 個文件被更改,包括 17 次插入2 次删除
  1. 17 2
      mystic.cpp

+ 17 - 2
mystic.cpp

@@ -47,6 +47,16 @@ static void file_output_open(const char *const log_path) {
 
 
 #include "lastseen.h"
 #include "lastseen.h"
 
 
+// http://c-faq.com/lib/randrange.html
+int randint(int N) { return rand() / (RAND_MAX / N + 1); }
+
+// http://c-faq.com/lib/randrange.html
+// numbers in the range [M, N] could be generated with something like
+
+int randrange(int M, int N) {
+  return M + rand() / (RAND_MAX / (N - M + 1) + 1);
+}
+
 /*
 /*
 What is the name of the actual, real Mystic executable
 What is the name of the actual, real Mystic executable
 that we'll be executing and mangling?
 that we'll be executing and mangling?
@@ -902,6 +912,8 @@ void render(int fd, const char *string_out) {
 
 
 // Beanzilla's no repeats
 // Beanzilla's no repeats
 
 
+#ifdef NOPE
+
 /**
 /**
  * have_seen( list, len, item )
  * have_seen( list, len, item )
  *
  *
@@ -941,6 +953,8 @@ void init_have_seen(int *list, int len) {
   }
   }
 }
 }
 
 
+#endif
+
 /*
 /*
     These are harry "timeout" events.
     These are harry "timeout" events.
 
 
@@ -984,8 +998,9 @@ void harry_idle_event(int fd) {
   // and don't repeat (the last two)!
   // and don't repeat (the last two)!
 
 
   do {
   do {
-    r = random() % ((sizeof(phrases) / sizeof(char *)) - 1);
-  } while (!last_seen_harry_event.seen_before(r));
+    r = randint((sizeof(phrases) / sizeof(char *)));
+    // r = random() % ((sizeof(phrases) / sizeof(char *)) - 1);
+  } while (last_seen_harry_event.seen_before(r));
 
 
   // ZF_LOGD("%d => %d %d", r, last_seen_harry_event[0],
   // ZF_LOGD("%d => %d %d", r, last_seen_harry_event[0],
   // last_seen_harry_event[1]);
   // last_seen_harry_event[1]);