From 2698e739660516af442c0f913eb0e91a00e7b7db Mon Sep 17 00:00:00 2001 From: Andreas Hansson Date: Wed, 3 Sep 2014 07:42:54 -0400 Subject: base: Use the global Mersenne twister throughout This patch tidies up random number generation to ensure that it is done consistently throughout the code base. In essence this involves a clean-up of Ruby, and some code simplifications in the traffic generator. As part of this patch a bunch of skewed distributions (off-by-one etc) have been fixed. Note that a single global random number generator is used, and that the object instantiation order will impact the behaviour (the sequence of numbers will be unaffected, but if module A calles random before module B then they would obviously see a different outcome). The dependency on the instantiation order is true in any case due to the execution-model of gem5, so we leave it as is. Also note that the global ranom generator is not thread safe at this point. Regressions using the memtest, TrafficGen or any Ruby tester are affected and will be updated accordingly. --- src/cpu/testers/networktest/networktest.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/cpu/testers/networktest') diff --git a/src/cpu/testers/networktest/networktest.cc b/src/cpu/testers/networktest/networktest.cc index 8fff53aa7..c2d34489b 100644 --- a/src/cpu/testers/networktest/networktest.cc +++ b/src/cpu/testers/networktest/networktest.cc @@ -35,6 +35,7 @@ #include #include "base/misc.hh" +#include "base/random.hh" #include "base/statistics.hh" #include "cpu/testers/networktest/networktest.hh" #include "debug/NetworkTest.hh" @@ -143,7 +144,7 @@ NetworkTest::tick() // - send pkt if this number is < injRate*(10^precision) bool send_this_cycle; double injRange = pow((double) 10, (double) precision); - unsigned trySending = random() % (int) injRange; + unsigned trySending = random_mt.random(0, (int) injRange); if (trySending < injRate*injRange) send_this_cycle = true; else @@ -174,7 +175,7 @@ NetworkTest::generatePkt() { unsigned destination = id; if (trafficType == 0) { // Uniform Random - destination = random() % numMemories; + destination = random_mt.random(0, numMemories - 1); } else if (trafficType == 1) { // Tornado int networkDimension = (int) sqrt(numMemories); int my_x = id%networkDimension; @@ -232,7 +233,7 @@ NetworkTest::generatePkt() // MemCmd::Command requestType; - unsigned randomReqType = random() % 3; + unsigned randomReqType = random_mt.random(0, 2); if (randomReqType == 0) { // generate packet for virtual network 0 requestType = MemCmd::ReadReq; -- cgit v1.2.3