# HG changeset patch
# User jacint
# Date 1083777784 0
# Node ID 22ce98f7d0f1f3f516801bef2615b3bd22ffe0e3
# Parent  04eb0d9022c807eed91227168b97d9d9c0f2ca83
primitive random graph generator

diff -r 04eb0d9022c8 -r 22ce98f7d0f1 src/work/jacint/graph_gen.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/work/jacint/graph_gen.h	Wed May 05 17:23:04 2004 +0000
@@ -0,0 +1,52 @@
+// -*- c++ -*-
+//randomGraph(i,j) gives a random graph on i nodes and j edges.
+#include <vector>
+#include <cstdlib>
+
+//#include <list_graph.h>
+//#include <time_measure.h>
+//#include <for_each_macros.h>
+//#include <bfs_iterator.h>
+//#include <bipartite_graph_wrapper.h>
+//#include <maps.h>
+//#include <max_flow.h>
+
+namespace hugo {
+
+
+  /**
+   * Inicializalja a veletlenszamgeneratort.
+   * Figyelem, ez nem jo igazi random szamokhoz,
+   * erre ne bizzad a titkaidat!
+   */
+  void random_init()
+  {
+    unsigned int seed = getpid();
+    seed |= seed << 15;
+    seed ^= time(0);
+
+    srand(seed);
+  }
+
+
+  /**
+   * Egy veletlen int-et ad vissza 0 es m-1 kozott.
+   */
+  int random(int m)
+  {
+    return int( double(m) * rand() / (RAND_MAX + 1.0) );
+  }
+
+
+  template<typename Graph>
+  void randomGraph (Graph& g, int n, int m) {
+    typedef typename Graph::Node Node;
+    g.clear();
+    std::vector<Node> nodes;
+    for (int i=0; i<n; ++i)
+      nodes.push_back(g.addNode());
+    for (int i=0; i<m; ++i) 
+      g.addEdge(nodes[random(n)], nodes[random(n)]);
+  }
+
+}