title: Implementing common random numbers in a simulation
body: <p>I am building a small simulation in Python and I would like to use <a href="http://en.wikipedia.org/wiki/Variance_reduction">Common Random Numbers</a> to reduce variation.  I know that I must achieve synchronization for CRN to work:</p>
  
  <blockquote>
    <p>CRN requires synchronization of the random number streams, which ensures that in addition to using the same random numbers to simulate all configurations, a specific random number used for a specific purpose in one configuration is used for exactly the same purpose in all other configurations.</p>
  </blockquote>
  
  <p>I was wondering if the way I wanted to implement it in my simulation was valid or if I should be using a different approach.</p>
  
  <p>My simulation has three different classes (ClassA, ClassB, ClassC), and ClassA objects have random travel times, ClassB objects have random service times and random usage rates, and ClassC objects have random service times.  Of course there can be multiple instances of each class of object.</p>
  
  <p>At the start of the simulation I specify a single random number seed (<code>replication_seed</code>) so that I can use a different seed for each simulation replication.</p>
  
  <pre><code>import numpy.random as npr
  rep_rnd_strm = npr.RandomState().seed(replication_seed)
  </code></pre>
  
  <p>Then in the constructor for each Class, I use <code>rep_rnd_strm</code> to generate a seed that is used to initialize the random number stream for the instance of the class:</p>
  
  <pre><code>self.class_rnd_strm = npr.RandomState().seed(rep_rnd_strm.randint(10000000))
  </code></pre>
  
  <p>I then use <code>self.class_rnd_strm</code> to generate a seed for each random number stream needed for the class instance.  For example the constructor of ClassA has:</p>
  
  <pre><code>self.travel_time_strm = npr.RandomState().seed(self.class_rnd_strm.randint(10000000))
  </code></pre>
  
  <p>while the constructor of ClassB has:</p>
  
  <pre><code>self.service_time_strm = npr.RandomState().seed(self.class_rnd_strm.randint(10000000))
  self.usage_rate_strm = npr.RandomState().seed(self.class_rnd_strm.randint(10000000))
  </code></pre>
  
  <p>Is what I am doing here a valid approach to getting synchronization to work, or should I be doing things differently?</p>