Fix for coverity #29409 - Use char 0 instead of NULL
[supertux.git] / src / math / random_generator.cpp
index 83d424b..6429c53 100644 (file)
 // Transliterated into C++ Allen King 060417, from sources on
 //          http://www.jbox.dk/sanos/source/lib/random.c.html
 
-#include <cassert>
+#include <assert.h>
 #include <stdexcept>
 #include <stdio.h>
 #include <time.h>
 
 #include "math/random_generator.hpp"
 
-RandomGenerator systemRandom;               // global random number generator
-
-RandomGenerator::RandomGenerator() {
+RandomGenerator graphicsRandom;               // graphic RNG
+RandomGenerator gameRandom;                   // game RNG
+
+RandomGenerator::RandomGenerator() :
+  initialized(),
+  fptr(),
+  rptr(),
+  state(),
+  rand_type(),
+  rand_deg(),
+  rand_sep(),
+  end_ptr(),
+  debug()
+{
   assert(sizeof(int) >= 4);
   initialized = 0;
   debug = 0;                              // change this by hand for debug
@@ -76,11 +87,10 @@ int RandomGenerator::rand() {
 }
 
 int RandomGenerator::rand(int v) {
-  assert(v >= 0 && v <= RandomGenerator::rand_max); // illegal arg
+  assert(v >= 0); // illegal arg
 
   // remove biases, esp. when v is large (e.g. v == (rand_max/4)*3;)
   int rv, maxV =(RandomGenerator::rand_max / v) * v;
-  assert(maxV <= RandomGenerator::rand_max);
   while ((rv = RandomGenerator::random()) >= maxV)
     ;
   return rv % v;                          // mod it down to 0..(maxV-1)