Package org.apache.commons.math3.random

Examples of org.apache.commons.math3.random.MersenneTwister.nextInt()


        int remainingPoints = crossoverPoints;
        int lastIndex = 0;
        for (int i = 0; i < crossoverPoints; i++, remainingPoints--) {
            // select the next crossover point at random
            final int crossoverIndex = 1 + lastIndex + random.nextInt(length - lastIndex - remainingPoints);

            // copy the current segment
            for (int j = lastIndex; j < crossoverIndex; j++) {
                c1.add(parent1Rep.get(j));
                c2.add(parent2Rep.get(j));
View Full Code Here


    @Test
    public void testLargeSamples() {
        RandomGenerator random = new Well1024a(0xa2a63cad12c01fb2l);
        for (int k = 0; k < 100; ++k) {
            int nbPoints = random.nextInt(10000);
            List<Vector2D> points = new ArrayList<Vector2D>();
            for (int i = 0; i < nbPoints; ++i) {
                double x = random.nextDouble();
                double y = random.nextDouble();
                points.add(new Vector2D(x, y));
View Full Code Here

    FastIDSet actual = new FastIDSet(1);
    Collection<Integer> expected = new HashSet<Integer>(1000000);
    RandomGenerator r = RandomManager.getRandom();
    for (int i = 0; i < 1000000; i++) {
      double d = r.nextDouble();
      Integer key = r.nextInt(100);
      if (d < 0.4) {
        assertEquals(expected.contains(key), actual.contains(key));
      } else {
        if (d < 0.7) {
          assertEquals(expected.add(key), actual.add(key));
View Full Code Here

    FastByIDFloatMap actual = new FastByIDFloatMap();
    Map<Long,Float> expected = Maps.newHashMapWithExpectedSize(1000000);
    RandomGenerator r = RandomManager.getRandom();
    for (int i = 0; i < 1000000; i++) {
      double d = r.nextDouble();
      Long key = (long) r.nextInt(100);
      if (d < 0.4) {
        Number expectedValue = expected.get(key);
        float actualValue = actual.get(key);
        if (expectedValue == null) {
          assertNaN(actualValue);
View Full Code Here

  @Test
  public void testNextBitSetRandom() {
    RandomGenerator random = RandomManager.getRandom();
    for (int i = 0; i < 100; i++) {
      BitSet bitSet = new BitSet(NUM_BITS);
      for (int j = 0; j < 20 + random.nextInt(50); j++) {
        bitSet.set(random.nextInt(NUM_BITS));
      }
      int from = random.nextInt(NUM_BITS);
      int nextSet = bitSet.nextSetBit(from);
      if (nextSet == -1) {
View Full Code Here

  public void testNextBitSetRandom() {
    RandomGenerator random = RandomManager.getRandom();
    for (int i = 0; i < 100; i++) {
      BitSet bitSet = new BitSet(NUM_BITS);
      for (int j = 0; j < 20 + random.nextInt(50); j++) {
        bitSet.set(random.nextInt(NUM_BITS));
      }
      int from = random.nextInt(NUM_BITS);
      int nextSet = bitSet.nextSetBit(from);
      if (nextSet == -1) {
        for (int j = from; j < NUM_BITS; j++) {
View Full Code Here

    for (int i = 0; i < 100; i++) {
      BitSet bitSet = new BitSet(NUM_BITS);
      for (int j = 0; j < 20 + random.nextInt(50); j++) {
        bitSet.set(random.nextInt(NUM_BITS));
      }
      int from = random.nextInt(NUM_BITS);
      int nextSet = bitSet.nextSetBit(from);
      if (nextSet == -1) {
        for (int j = from; j < NUM_BITS; j++) {
          assertFalse(bitSet.get(j));
        }
View Full Code Here

    FastByIDMap<String> actual = new FastByIDMap<String>();
    Map<Long, String> expected = Maps.newHashMapWithExpectedSize(1000000);
    RandomGenerator r = RandomManager.getRandom();
    for (int i = 0; i < 1000000; i++) {
      double d = r.nextDouble();
      Long key = (long) r.nextInt(100);
      if (d < 0.4) {
        assertEquals(expected.get(key), actual.get(key));
      } else {
        if (d < 0.7) {
          assertEquals(expected.put(key, "bang"), actual.put(key, "bang"));
View Full Code Here

        int remainingPoints = crossoverPoints;
        int lastIndex = 0;
        for (int i = 0; i < crossoverPoints; i++, remainingPoints--) {
            // select the next crossover point at random
            final int crossoverIndex = 1 + lastIndex + random.nextInt(length - lastIndex - remainingPoints);

            // copy the current segment
            for (int j = lastIndex; j < crossoverIndex; j++) {
                c1.add(parent1Rep.get(j));
                c2.add(parent2Rep.get(j));
View Full Code Here

        final Set<T> child1Set = new HashSet<T>(length);
        final Set<T> child2Set = new HashSet<T>(length);

        final RandomGenerator random = GeneticAlgorithm.getRandomGenerator();
        // choose random points, making sure that lb < ub.
        int a = random.nextInt(length);
        int b;
        do {
            b = random.nextInt(length);
        } while (a == b);
        // determine the lower and upper bounds
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.