當前位置: 首頁>>代碼示例>>Java>>正文


Java RandomGenerator.nextInt方法代碼示例

本文整理匯總了Java中org.apache.commons.math3.random.RandomGenerator.nextInt方法的典型用法代碼示例。如果您正苦於以下問題:Java RandomGenerator.nextInt方法的具體用法?Java RandomGenerator.nextInt怎麽用?Java RandomGenerator.nextInt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.math3.random.RandomGenerator的用法示例。


在下文中一共展示了RandomGenerator.nextInt方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testLargeSamples

import org.apache.commons.math3.random.RandomGenerator; //導入方法依賴的package包/類
@Test
public void testLargeSamples() throws IOException {
    RandomGenerator random = new Well1024a(0x35ddecfc78131e1dl);
    final UnitSphereRandomVectorGenerator sr = new UnitSphereRandomVectorGenerator(3, random);
    for (int k = 0; k < 50; ++k) {

        // define the reference sphere we want to compute
        double d = 25 * random.nextDouble();
        double refRadius = 10 * random.nextDouble();
        Vector3D refCenter = new Vector3D(d, new Vector3D(sr.nextVector()));
        // set up a large sample inside the reference sphere
        int nbPoints = random.nextInt(1000);
        List<Vector3D> points = new ArrayList<Vector3D>();
        for (int i = 0; i < nbPoints; ++i) {
            double r = refRadius * random.nextDouble();
            points.add(new Vector3D(1.0, refCenter, r, new Vector3D(sr.nextVector())));
        }

        // test we find a sphere at most as large as the one used for random drawings
        checkSphere(points, refRadius);

    }
}
 
開發者ID:Quanticol,項目名稱:CARMA,代碼行數:24,代碼來源:WelzlEncloser3DTest.java

示例2: uniformSelect

import org.apache.commons.math3.random.RandomGenerator; //導入方法依賴的package包/類
public static <T> T uniformSelect( Collection<T> collection ) {
	if (collection.size()==0) {
		System.out.println("IS EMPTY!!!");
		return null;
	}
	int idx = 0;
	if (collection.size()>1) {
		RandomGenerator rg = getInstance().get();
		idx = rg.nextInt(collection.size());
	}
	int counter = 0;
	T last = null;
	for (T t : collection) {
		last = t;
		if (counter == idx) {
			return t;
		} else {
			counter++;
		}
	}
	return last;
}
 
開發者ID:Quanticol,項目名稱:CARMA,代碼行數:23,代碼來源:RandomGeneratorRegistry.java

示例3: randomize

import org.apache.commons.math3.random.RandomGenerator; //導入方法依賴的package包/類
@Override
public Iterator<E> randomize(final RandomGenerator random) {
    return new Iterator<E>() {

        private final int size = sample.size();
        private int resampleIdx = 0;

        @Override
        public boolean hasNext() {
            return resampleIdx < size;
        }

        @Override
        public E next() {
            final int sourceIdx = random.nextInt(size);
            resampleIdx++;
            return sample.get(sourceIdx);
        }

    };
}
 
開發者ID:subes,項目名稱:invesdwin-util,代碼行數:22,代碼來源:BootstrapRandomizer.java

示例4: randomize

import org.apache.commons.math3.random.RandomGenerator; //導入方法依賴的package包/類
@Override
public Iterator<E> randomize(final RandomGenerator random) {
    return new Iterator<E>() {

        private int resampleIdx = 0;

        @Override
        public boolean hasNext() {
            return resampleIdx < sampleSize;
        }

        @Override
        public E next() {
            final List<E> sampleChunk = getSampleChunk(random);
            final int sourceIdx = random.nextInt(sampleChunk.size());
            resampleIdx++;
            return sampleChunk.get(sourceIdx);
        }

    };
}
 
開發者ID:subes,項目名稱:invesdwin-util,代碼行數:22,代碼來源:WeightedChunksAscendingRandomizer.java

示例5: sample

import org.apache.commons.math3.random.RandomGenerator; //導入方法依賴的package包/類
/**
 * Sample a dataset
 * @param numSamples the number of samples to getFromOrigin
 * @param rng the rng to use
 * @param withReplacement whether to allow duplicates (only tracked by example row number)
 * @return the sample dataset
 */
@Override
public DataSet sample(int numSamples, RandomGenerator rng, boolean withReplacement) {
    if(numSamples >= numExamples())
        return this;
    else {
        INDArray examples = Nd4j.create(numSamples, getFeatures().columns());
        INDArray outcomes = Nd4j.create(numSamples, numOutcomes());
        Set<Integer> added = new HashSet<Integer>();
        for(int i = 0; i < numSamples; i++) {
            int picked = rng.nextInt(numExamples());
            if(!withReplacement)
                while(added.contains(picked)) {
                    picked = rng.nextInt(numExamples());

                }
            examples.putRow(i,get(picked).getFeatures());
            outcomes.putRow(i,get(picked).getLabels());

        }
        return new DataSet(examples,outcomes);
    }
}
 
開發者ID:wlin12,項目名稱:JNN,代碼行數:30,代碼來源:DataSet.java

示例6: generate

import org.apache.commons.math3.random.RandomGenerator; //導入方法依賴的package包/類
@Override
public Pair<String,String> generate(int id, RandomGenerator random) {
  int user = random.nextInt(numUsers);
  int randProduct = random.nextInt(numProducts);
  // Want product === user mod features
  int product = ((user % features) + (randProduct / features) * features) % numProducts;
  String datum = ALSUtilsTest.idToStringID(user) + "," + ALSUtilsTest.idToStringID(product) +
      ",1," + System.currentTimeMillis();
  return new Pair<>(Integer.toString(id), datum);
}
 
開發者ID:oncewang,項目名稱:oryx2,代碼行數:11,代碼來源:FeaturesALSDataGenerator.java

示例7: generate

import org.apache.commons.math3.random.RandomGenerator; //導入方法依賴的package包/類
@Override
public Pair<String,String> generate(int id, RandomGenerator random) {
  String userString = ALSUtilsTest.idToStringID(random.nextInt(numUsers));
  String itemString = ALSUtilsTest.idToStringID(random.nextInt(numProducts));
  int rating = random.nextInt(maxRating - minRating + 1) + minRating;
  String datum = userString + "," +  itemString + "," + rating + "," + System.currentTimeMillis();
  return new Pair<>(Integer.toString(id), datum);
}
 
開發者ID:oncewang,項目名稱:oryx2,代碼行數:9,代碼來源:RandomALSDataGenerator.java

示例8: generate

import org.apache.commons.math3.random.RandomGenerator; //導入方法依賴的package包/類
@Override
public Pair<String,String> generate(int id, RandomGenerator random) {
  return new Pair<>(Integer.toString(id),
                    id + "," +
                    random.nextInt(100) + ',' +
                    random.nextBoolean() + ',' +
                    random.nextGaussian());
}
 
開發者ID:oncewang,項目名稱:oryx2,代碼行數:9,代碼來源:DefaultCSVDatumGenerator.java

示例9: getDestination

import org.apache.commons.math3.random.RandomGenerator; //導入方法依賴的package包/類
public static int getDestination(double now, int loc, RandomGenerator r) {
		if (loc == getLocId(1, 1)) {
			return r.nextInt(NUMBER_OF_LOCATIONS);
		} else {
			return getLocId(1, 1);
		}
//		return r.nextInt(NUMBER_OF_LOCATIONS);
	}
 
開發者ID:Quanticol,項目名稱:CARMA,代碼行數:9,代碼來源:SmartTaxisDefinitions.java

示例10: testLargeSamples

import org.apache.commons.math3.random.RandomGenerator; //導入方法依賴的package包/類
@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));
        }
        checkDisk(points);
    }
}
 
開發者ID:Quanticol,項目名稱:CARMA,代碼行數:15,代碼來源:WelzlEncloser2DTest.java

示例11: testFloorDivModInt

import org.apache.commons.math3.random.RandomGenerator; //導入方法依賴的package包/類
@Test
public void testFloorDivModInt() {
    RandomGenerator generator = new Well1024a(0x7ccab45edeaab90al);
    for (int i = 0; i < 10000; ++i) {
        int a = generator.nextInt();
        int b = generator.nextInt();
        if (b == 0) {
            try {
                FastMath.floorDiv(a, b);
                Assert.fail("an exception should have been thrown");
            } catch (MathArithmeticException mae) {
                // expected
            }
        } else {
            int d = FastMath.floorDiv(a, b);
            int m = FastMath.floorMod(a, b);
            Assert.assertEquals(FastMath.toIntExact(poorManFloorDiv(a, b)), d);
            Assert.assertEquals(FastMath.toIntExact(poorManFloorMod(a, b)), m);
            Assert.assertEquals(a, d * b + m);
            if (b < 0) {
                Assert.assertTrue(m <= 0);
                Assert.assertTrue(-m < -b);
            } else {
                Assert.assertTrue(m >= 0);
                Assert.assertTrue(m < b);
            }
        }
    }
}
 
開發者ID:Quanticol,項目名稱:CARMA,代碼行數:30,代碼來源:FastMathTest.java

示例12: randomPositions

import org.apache.commons.math3.random.RandomGenerator; //導入方法依賴的package包/類
public static List<SimpleInterval> randomPositions(final String contig, final int chainLength, final RandomGenerator rng, final double separationScale) {
    final List<SimpleInterval> positions = new ArrayList<>();
    int position = 1;
    for (int n = 0; n < chainLength; n++) {
        position += rng.nextInt((int) separationScale);
        final SimpleInterval interval = new SimpleInterval(contig, position, position);
        positions.add(interval);
    }
    return positions;
}
 
開發者ID:broadinstitute,項目名稱:gatk-protected,代碼行數:11,代碼來源:CopyRatioSegmenterUnitTest.java

示例13: setValueToRandom

import org.apache.commons.math3.random.RandomGenerator; //導入方法依賴的package包/類
@Override
public void setValueToRandom(RandomGenerator rg) {
    size = rg.nextInt(maxSize);
    super.setValueToRandom(rg);
}
 
開發者ID:AVMf,項目名稱:avmf,代碼行數:6,代碼來源:StringVariable.java

示例14: setValueToRandom

import org.apache.commons.math3.random.RandomGenerator; //導入方法依賴的package包/類
@Override
public void setValueToRandom(RandomGenerator randomGenerator) {
    int range = max - min + 1;
    int randomValue = randomGenerator.nextInt(range);
    setValue(min + randomValue);
}
 
開發者ID:AVMf,項目名稱:avmf,代碼行數:7,代碼來源:AtomicVariable.java

示例15: mate

import org.apache.commons.math3.random.RandomGenerator; //導入方法依賴的package包/類
/**
 * Helper for {@link #crossover(Chromosome, Chromosome)}. Performs the actual crossover.
 *
 * @param first the first chromosome
 * @param second the second chromosome
 * @return the pair of new chromosomes that resulted from the crossover
 * @throws DimensionMismatchException if the length of the two chromosomes is different
 * @throws NumberIsTooLargeException if the number of crossoverPoints is too large for the actual chromosomes
 */
private ChromosomePair mate(final AbstractListChromosome<T> first,
                            final AbstractListChromosome<T> second)
    throws DimensionMismatchException, NumberIsTooLargeException {

    final int length = first.getLength();
    if (length != second.getLength()) {
        throw new DimensionMismatchException(second.getLength(), length);
    }
    if (crossoverPoints >= length) {
        throw new NumberIsTooLargeException(crossoverPoints, length, false);
    }

    // array representations of the parents
    final List<T> parent1Rep = first.getRepresentation();
    final List<T> parent2Rep = second.getRepresentation();
    // and of the children
    final List<T> child1Rep = new ArrayList<T>(length);
    final List<T> child2Rep = new ArrayList<T>(length);

    final RandomGenerator random = GeneticAlgorithm.getRandomGenerator();

    List<T> c1 = child1Rep;
    List<T> c2 = child2Rep;

    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));
        }

        // swap the children for the next segment
        List<T> tmp = c1;
        c1 = c2;
        c2 = tmp;

        lastIndex = crossoverIndex;
    }

    // copy the last segment
    for (int j = lastIndex; j < length; j++) {
        c1.add(parent1Rep.get(j));
        c2.add(parent2Rep.get(j));
    }

    return new ChromosomePair(first.newFixedLengthChromosome(child1Rep),
                              second.newFixedLengthChromosome(child2Rep));
}
 
開發者ID:biocompibens,項目名稱:SME,代碼行數:63,代碼來源:NPointCrossover.java


注:本文中的org.apache.commons.math3.random.RandomGenerator.nextInt方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。