MATSIM
MatsimRandom.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * MatsimRandom.java
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 2008 by the members listed in the COPYING, *
8  * LICENSE and WARRANTY file. *
9  * email : info at matsim dot org *
10  * *
11  * *********************************************************************** *
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * See also COPYING, LICENSE and WARRANTY file *
18  * *
19  * *********************************************************************** */
20 
21 package org.matsim.core.gbl;
22 
23 import java.util.Random;
24 
25 
33 public abstract class MatsimRandom {
34  private static final long DEFAULT_RANDOM_SEED = 4711;
35 
36  private static long lastUsedSeed = DEFAULT_RANDOM_SEED;
37  private static int internalCounter = 0;
38 
40  private static final Random random = new Random(DEFAULT_RANDOM_SEED);
41 
43  public static void reset() {
44  reset(DEFAULT_RANDOM_SEED);
45  }
46 
51  public static void reset(final long seed) {
52  lastUsedSeed = seed;
53  internalCounter = 0;
54  getRandom().setSeed(seed);
55 // prepareRNG(random);
56  }
57  public static Random getRandom() {
58  return random;
59  }
60 
66  public static Random getLocalInstance() {
67  internalCounter++;
68  Random r = new Random(lastUsedSeed + internalCounter*23l);
69  prepareRNG(r);
70  return r;
71  }
72 
78  private static void prepareRNG(final Random rng) {
79  for (int i = 0; i < 100; i++) {
80  rng.nextDouble();
81  }
82  }
83 }
static final long DEFAULT_RANDOM_SEED
static void reset(final long seed)
static void prepareRNG(final Random rng)