From c7073650f6c6231fd8490c17f04d389131c3d65a Mon Sep 17 00:00:00 2001 From: Ciaran McCreesh <0402749m@student.gla.ac.uk> Date: Thu, 21 Jun 2012 17:02:58 +0100 Subject: [PATCH] Pass in a seeded random number generator --- examples/graphgen/graphgen.cpp | 18 ++++++++++++------ 1 files changed, 12 insertions(+), 6 deletions(-) diff --git a/examples/graphgen/graphgen.cpp b/examples/graphgen/graphgen.cpp index 1c22419..5f84886 100644 --- a/examples/graphgen/graphgen.cpp +++ b/examples/graphgen/graphgen.cpp @@ -1,4 +1,6 @@ #include "stdafx.h" +#include +#include int main(int argc, char* argv[]) { Env = TEnv(argc, argv, TNotify::StdNotify); @@ -21,6 +23,10 @@ int main(int argc, char* argv[]) { const int M = Env.GetIfArgPrefixInt("-m:", 5000, "Number of edges"); const double P = Env.GetIfArgPrefixFlt("-p:", 0.1, "Probability/Degree-exponent"); const int K = Env.GetIfArgPrefixInt("-k:", 3, "Degree"); + TRnd R; + timeval tv; + gettimeofday(&tv, 0); + R.PutSeed(tv.tv_usec); if (Env.IsEndOfRun()) { return 0; } TExeTm ExeTm; @@ -40,27 +46,27 @@ int main(int argc, char* argv[]) { DescStr = TStr::Fmt("Undirected 2D grid of %d rows and %d columns.", N, M); } else if (Plot == "e") { - G = TSnap::GenRndGnm(N, M, false); + G = TSnap::GenRndGnm(N, M, false, R); DescStr = TStr::Fmt("Undirected Erdos-Renyi random graph."); } else if (Plot == "k") { - G = TSnap::GenRndDegK(N, K); + G = TSnap::GenRndDegK(N, K, 100, R); DescStr = TStr::Fmt("Undirected k-regular random graph (every node has degree K)."); } else if (Plot == "b") { - G = TSnap::GenPrefAttach(N, K); + G = TSnap::GenPrefAttach(N, K, R); DescStr = TStr::Fmt("Undirected Albert-Barabasi Preferential Attachment graph (each new node creades k preferentially attached edges)."); } else if (Plot == "p") { - G = TSnap::GenRndPowerLaw(N, P, true); + G = TSnap::GenRndPowerLaw(N, P, true, R); DescStr = TStr::Fmt("Random Graph with Power-Law degree distribution with exponent P."); } else if (Plot == "c") { - G = TSnap::ConvertGraph(TSnap::GenCopyModel(N, P)); + G = TSnap::ConvertGraph(TSnap::GenCopyModel(N, P, R)); DescStr = TStr::Fmt("Copying model by Kleinberg et al. Node u comes, selects a random v, and with prob P it links to v, with 1-P links u links to neighbor of v. Power-law degree slope is 1/(1-P)."); } else if (Plot == "w") { - G = TSnap::GenSmallWorld(N, K, P); + G = TSnap::GenSmallWorld(N, K, P, R); DescStr = TStr::Fmt("Watts-Strogatz Small-world model. Every node links to K other nodes."); } printf("done.\n"); -- 1.6.5.2