Codota Logo
MersenneTwister
Code IndexAdd Codota to your IDE (free)

How to use
MersenneTwister
in
org.apache.commons.math3.random

Best Java code snippets using org.apache.commons.math3.random.MersenneTwister (Showing top 20 results out of 369)

Refine searchRefine arrow

  • RandomGenerator
  • Common ways to obtain MersenneTwister
private void myMethod () {
MersenneTwister m =
  • Codota Iconnew MersenneTwister()
  • Codota Iconnew MersenneTwister(seed)
  • Smart code suggestions by Codota
}
origin: org.apache.commons/commons-math3

/**
 * Create an object that will use a default RNG ({@link MersenneTwister}),
 * in order to generate the individual components.
 *
 * @param dimension Space dimension.
 */
public UnitSphereRandomVectorGenerator(final int dimension) {
  this(dimension, new MersenneTwister());
}
origin: apache/flink

  @Override
  public MersenneTwister generator() {
    MersenneTwister random = new MersenneTwister();
    random.setSeed(seed);
    return random;
  }
}
origin: opentripplanner/OpenTripPlanner

  public void randomize () {
    for (TIntObjectIterator<int[]> it = offsets.iterator(); it.hasNext();) {
      it.advance();
      int[] newVal = new int[it.value().length];

      RaptorWorkerTimetable tt = data.timetablesForPattern.get(it.key());

      for (int i = 0; i < newVal.length; i++) {
        newVal[i] = mt.nextInt(tt.headwaySecs[i]);
      }

      it.setValue(newVal);
    }

  }
}
origin: org.apache.commons/commons-math3

  setSeed(System.currentTimeMillis() + System.identityHashCode(this));
  return;
setSeed(19650218);
int i = 1;
int j = 0;
clear(); // Clear normal deviate cache
origin: opentripplanner/OpenTripPlanner

  public static void main (String... args) {
    System.out.println("Testing histogram store with normal distribution, mean 0");
    Histogram h = new Histogram("Normal");

    MersenneTwister mt = new MersenneTwister();

    IntStream.range(0, 1000000).map(i -> (int) Math.round(mt.nextGaussian() * 20 + 2.5)).forEach(h::add);

    h.displayHorizontal();
    System.out.println("mean: " + h.mean());
  }
}
origin: rinde/RinSim

 @Override
 public RandomGenerator sharedInstance(Class<?> clazz) {
  stateCheck();
  if (!classRngMap.containsKey(clazz)) {
   final RandomGenerator rng = new UnmodifiableRandomGenerator(
    new MersenneTwister(masterRandomGenerator.nextLong()));
   classRngMap.put(clazz, rng);
   return rng;
  }
  return classRngMap.get(clazz);
 }
}
origin: matsim-org/matsim

  /**
   * Returns an instance of a random number generator, which can be used locally, e.g. in threads.
   */
  public static RandomGenerator getLocalGenerator() {
    return new MersenneTwister(rg.nextInt());
  }
}
origin: rinde/RinSim

     .build())));
final RandomGenerator rng = new MersenneTwister(seed);
for (int i = 0; i < 20; i++) {
 final long announceTime = rng.nextInt(DoubleMath.roundToInt(
  endTime * .8, RoundingMode.FLOOR));
 b.addEvent(AddParcelEvent.create(Parcel
  .builder(
   new Point(rng.nextDouble() * 10, rng.nextDouble() * 10),
   new Point(rng.nextDouble() * 10, rng.nextDouble() * 10))
  .orderAnnounceTime(announceTime)
origin: rinde/RinSim

final RandomGenerator rng = new MersenneTwister(123);
final double startLengthOfDay = 1000;
final int repetitions = 3;
  final List<Double> scenario = newArrayList();
  for (int i = 0; i < events; i++) {
   scenario.add(rng.nextDouble() * startLengthOfDay);
origin: rinde/RinSim

/**
 * Tests determinism of arrival times generators, given the same random number
 * generator and seed they should always return the same sequence.
 */
@Test
public void determinismTest() {
 final RandomGenerator outer = new MersenneTwister(123);
 for (int i = 0; i < 100; i++) {
  final long seed = outer.nextLong();
  final RandomGenerator inner = new MersenneTwister(seed);
  final List<Double> list1 = poisson.generate(inner.nextLong());
  for (int j = 0; j < 100; j++) {
   inner.setSeed(seed);
   final List<Double> list2 = poisson.generate(inner.nextLong());
   assertEquals(list1, list2);
  }
 }
}
origin: apache/mahout

RandomWrapper() {
 random = new MersenneTwister();
 random.setSeed(System.currentTimeMillis() + System.identityHashCode(random));
}
origin: stackoverflow.com

 class RandomVariable {

/** Initialize Mersenne Twister generator. */
private static MersenneTwister rnd = new MersenneTwister();

public static double rand() {
  return rnd.nextDouble();
}

/** Generate a random number from a uniform random variable.
 *
 *  @param  min Mininum value for the random variable.
 *  @param  max Maximum value for the random variable.
 *
 *  @return     A random double between min and max.
 */
public static double uniform(double min, double max) {
  return min + (max - min) * rand();
}
}
origin: stackoverflow.com

 MersenneTwister rng = new MersenneTwister();
rng.setSeed(new int[] {1234567890});
System.out.println(rng.nextInt(Integer.MAX_VALUE)); // 1977150888
origin: com.conveyal/gtfs-lib

MersenneTwister twister = new MersenneTwister();
final int length = 27;
char[] chars = new char[length];
for (int i = 0; i < length; i++) {
  chars[i] = (char) ('a' + twister.nextInt(26));
origin: OpenHFT/Chronicle-TimeSeries

BytesStore trend = NativeBytesStore.lazyNativeBytesStoreWithFixedCapacity(trendLength * 8L);
double x = start;
RandomGenerator rand = new MersenneTwister();
for (int i = 0; i < trendLength - 1; i++) {
  float f = rand.nextFloat();
  trend.writeDouble((long) i << 3, x);
  x += nd.inverseCumulativeProbability(f);
  tasks.add(fjp.submit(() -> {
    NormalDistribution nd2 = new NormalDistribution(0, sd2);
    RandomGenerator rand2 = new MersenneTwister();
    for (int j = si; j < ei; j++) {
      generateBrownian(col,
origin: apache/flink

public MersenneTwisterFactory(long seed) {
  random.setSeed(seed);
}
origin: apache/flink

@Override
protected MersenneTwisterGenerable next() {
  return new MersenneTwisterGenerable(random.nextLong());
}
origin: jMetal/jMetal

@Override
public double nextDouble(double lowerBound, double upperBound) {
 return lowerBound + rnd.nextDouble()*(upperBound - lowerBound) ;
}
origin: rinde/RinSim

@Override
public RandomGenerator newInstance() {
 stateCheck();
 return new MersenneTwister(masterRandomGenerator.nextLong());
}
origin: rinde/RinSim

@Test
public void testRandomNode() {
 final RandomGenerator rnd = new MersenneTwister(456);
 for (int i = 0; i < 500; i++) {
  Graphs.addBiPath(graph, new Point(rnd.nextInt(), rnd.nextInt()),
   new Point(rnd.nextInt(), rnd.nextInt()));
 }
 final Graph<LengthData> unmod = Graphs.unmodifiableGraph(graph);
 final Point p1 = graph.getRandomNode(new MersenneTwister(123));
 final Point p2 = unmod.getRandomNode(new MersenneTwister(123));
 assertEquals(p1, p2);
}
org.apache.commons.math3.randomMersenneTwister

Javadoc

This class implements a powerful pseudo-random number generator developed by Makoto Matsumoto and Takuji Nishimura during 1996-1997.

This generator features an extremely long period (219937-1) and 623-dimensional equidistribution up to 32 bits accuracy. The home page for this generator is located at http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html.

This generator is described in a paper by Makoto Matsumoto and Takuji Nishimura in 1998: Mersenne Twister: A 623-Dimensionally Equidistributed Uniform Pseudo-Random Number Generator, ACM Transactions on Modeling and Computer Simulation, Vol. 8, No. 1, January 1998, pp 3--30

This class is mainly a Java port of the 2002-01-26 version of the generator written in C by Makoto Matsumoto and Takuji Nishimura. Here is their original copyright:

Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. The names of its contributors may not be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Most used methods

  • <init>
    Creates a new random number generator using an int array seed.
  • setSeed
    Reinitialize the generator as if just built with the given int array seed.The state of the generator
  • nextInt
  • nextDouble
  • nextLong
  • clear
  • nextGaussian
  • nextBytes
  • nextBoolean

Popular in Java

  • Finding current android device location
  • scheduleAtFixedRate (Timer)
  • getExternalFilesDir (Context)
  • startActivity (Activity)
  • OutputStream (java.io)
    A writable sink for bytes.Most clients will use output streams that write data to the file system (
  • DecimalFormat (java.text)
    DecimalFormat is a concrete subclass ofNumberFormat that formats decimal numbers. It has a variety o
  • Stack (java.util)
    The Stack class represents a last-in-first-out (LIFO) stack of objects. It extends class Vector with
  • ExecutorService (java.util.concurrent)
    An Executor that provides methods to manage termination and methods that can produce a Future for tr
  • ImageIO (javax.imageio)
  • Reference (javax.naming)
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now