Browse Source

fillRandom now uses random() instead of rand()

- a generic improvement that fixes NetBSD test failure.
Tomek Mrugalski 13 years ago
parent
commit
c11a19fe6b

+ 2 - 1
src/bin/dhcp6/dhcp6_srv.cc

@@ -12,6 +12,7 @@
 // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 // PERFORMANCE OF THIS SOFTWARE.
 
+#include <stdlib.h>
 #include <time.h>
 #include <dhcp/dhcp6.h>
 #include <dhcp/pkt6.h>
@@ -220,7 +221,7 @@ void Dhcpv6Srv::setServerID() {
 
     // Length of the identifier is company specific. I hereby declare
     // ISC "standard" of 6 bytes long pseudo-random numbers.
-    srand(time(NULL));
+    srandom(time(NULL));
     fillRandom(&srvid[6],&srvid[12]);
 
     serverid_ = OptionPtr(new Option(Option::V6, D6O_SERVERID,

+ 2 - 2
src/lib/util/range_utilities.h

@@ -15,7 +15,7 @@
 #ifndef __RANGE_UTIL_H_
 #define __RANGE_UTIL_H_ 1
 
-#include <cstdlib>
+#include <stdlib.h>
 #include <algorithm>
 
 // This header contains useful methods for conduction operations on
@@ -58,7 +58,7 @@ template <typename Iterator>
 void
 fillRandom(Iterator begin, Iterator end) {
     for (Iterator x = begin; x != end; ++x) {
-        *x = std::rand();
+        *x = random();
     }
 }
 

+ 3 - 0
src/lib/util/tests/range_utilities_unittest.cc

@@ -14,6 +14,7 @@
 
 #include <config.h>
 #include <stdint.h>
+#include <stdlib.h>
 
 #include <gtest/gtest.h>
 #include <vector>
@@ -38,6 +39,8 @@ TEST(RangeUtilitiesTest, isZero) {
 
 TEST(RangeUtilitiesTest, randomFill) {
 
+    srandom(time(NULL));
+
     vector<uint8_t> vec1(16,0);
     vector<uint8_t> vec2(16,0);