当前位置: 首页>>代码示例>>Java>>正文


Java RandomData.nextInt方法代码示例

本文整理汇总了Java中org.apache.commons.math.random.RandomData.nextInt方法的典型用法代码示例。如果您正苦于以下问题:Java RandomData.nextInt方法的具体用法?Java RandomData.nextInt怎么用?Java RandomData.nextInt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.math.random.RandomData的用法示例。


在下文中一共展示了RandomData.nextInt方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testNormalizer

import org.apache.commons.math.random.RandomData; //导入方法依赖的package包/类
public void testNormalizer() {
	RandomData r = new RandomDataImpl();
	int size = 10000;
	short[] test = new short[size];

	for (int i = 0; i < size; i++) {
		test[i] = (short) r.nextInt(Short.MIN_VALUE, Short.MAX_VALUE);
	}

	double[] res = FrameUtil.normalize(test);

	double max = Double.MIN_VALUE;
	double min = Double.MAX_VALUE;
	for (int i = 0; i < res.length; i++) {
		max = res[i] > max ? max = res[i] : max;
		min = res[i] < min ? min = res[i] : min;
	}
	assertTrue(max <= 1.0d);
	assertTrue(min >= -1.0d);
}
 
开发者ID:mobilesec,项目名称:auth-client-demo-module-voice,代码行数:21,代码来源:FrameUtilTest.java

示例2: testWithInitialCapacity

import org.apache.commons.math.random.RandomData; //导入方法依赖的package包/类
@Test
public void testWithInitialCapacity() {

    ResizableDoubleArray eDA2 = new ResizableDoubleArray(2);
    Assert.assertEquals("Initial number of elements should be 0", 0, eDA2.getNumElements());

    RandomData randomData = new RandomDataImpl();
    int iterations = randomData.nextInt(100, 1000);

    for( int i = 0; i < iterations; i++) {
        eDA2.addElement( i );
    }

    Assert.assertEquals("Number of elements should be equal to " + iterations, iterations, eDA2.getNumElements());

    eDA2.addElement( 2.0 );

    Assert.assertEquals("Number of elements should be equals to " + (iterations +1),
            iterations + 1 , eDA2.getNumElements() );
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:21,代码来源:ResizableDoubleArrayTest.java

示例3: generatePartition

import org.apache.commons.math.random.RandomData; //导入方法依赖的package包/类
/**
 * Generates a partition of <sample> into up to 5 sequentially selected
 * subsamples with randomly selected partition points.
 * 
 * @param sample array to partition
 * @return rectangular array with rows = subsamples
 */
private double[][] generatePartition(double[] sample) {
    final int length = sample.length;
    final double[][] out = new double[5][];
    final RandomData randomData = new RandomDataImpl();
    int cur = 0;
    int offset = 0;
    int sampleCount = 0;
    for (int i = 0; i < 5; i++) {
        if (cur == length || offset == length) {
            break;
        }
        final int next = (i == 4 || cur == length - 1) ? length - 1 : randomData.nextInt(cur, length - 1);
        final int subLength = next - cur + 1;
        out[i] = new double[subLength];
        System.arraycopy(sample, offset, out[i], 0, subLength);
        cur = next + 1;
        sampleCount++;
        offset += subLength;
    }
    if (sampleCount < 5) {
        double[][] out2 = new double[sampleCount][];
        for (int j = 0; j < sampleCount; j++) {
            final int curSize = out[j].length;
            out2[j] = new double[curSize];
            System.arraycopy(out[j], 0, out2[j], 0, curSize);
        }
        return out2;
    } else {
        return out;
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:39,代码来源:AggregateSummaryStatisticsTest.java

示例4: generatePartition

import org.apache.commons.math.random.RandomData; //导入方法依赖的package包/类
/**
 * Generates a partition of <sample> into up to 5 sequentially selected
 * subsamples with randomly selected partition points.
 *
 * @param sample array to partition
 * @return rectangular array with rows = subsamples
 */
private double[][] generatePartition(double[] sample) {
    final int length = sample.length;
    final double[][] out = new double[5][];
    final RandomData randomData = new RandomDataImpl();
    int cur = 0;
    int offset = 0;
    int sampleCount = 0;
    for (int i = 0; i < 5; i++) {
        if (cur == length || offset == length) {
            break;
        }
        final int next = (i == 4 || cur == length - 1) ? length - 1 : randomData.nextInt(cur, length - 1);
        final int subLength = next - cur + 1;
        out[i] = new double[subLength];
        System.arraycopy(sample, offset, out[i], 0, subLength);
        cur = next + 1;
        sampleCount++;
        offset += subLength;
    }
    if (sampleCount < 5) {
        double[][] out2 = new double[sampleCount][];
        for (int j = 0; j < sampleCount; j++) {
            final int curSize = out[j].length;
            out2[j] = new double[curSize];
            System.arraycopy(out[j], 0, out2[j], 0, curSize);
        }
        return out2;
    } else {
        return out;
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:39,代码来源:AggregateSummaryStatisticsTest.java

示例5: generateSample

import org.apache.commons.math.random.RandomData; //导入方法依赖的package包/类
/**
 * Generates a random sample of double values.
 * Sample size is random, between 10 and 100 and values are
 * uniformly distributed over [-100, 100].
 *
 * @return array of random double values
 */
private double[] generateSample() {
    final RandomData randomData = new RandomDataImpl();
    final int sampleSize = randomData.nextInt(10,100);
    double[] out = new double[sampleSize];
    for (int i = 0; i < out.length; i++) {
        out[i] = randomData.nextUniform(-100, 100);
    }
    return out;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:17,代码来源:AggregateSummaryStatisticsTest.java

示例6: testWithInitialCapacity

import org.apache.commons.math.random.RandomData; //导入方法依赖的package包/类
public void testWithInitialCapacity() {
    
    ResizableDoubleArray eDA2 = new ResizableDoubleArray(2);
    assertEquals("Initial number of elements should be 0", 0, eDA2.getNumElements());
    
    RandomData randomData = new RandomDataImpl();
    int iterations = randomData.nextInt(100, 1000);
    
    for( int i = 0; i < iterations; i++) {
        eDA2.addElement( i );
    }
    
    assertEquals("Number of elements should be equal to " + iterations, iterations, eDA2.getNumElements());
    
    eDA2.addElement( 2.0 );
    
    assertEquals("Number of elements should be equals to " + (iterations +1),
            iterations + 1 , eDA2.getNumElements() );
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:20,代码来源:ResizableDoubleArrayTest.java

示例7: testWithInitialCapacityAndExpansionFactor

import org.apache.commons.math.random.RandomData; //导入方法依赖的package包/类
public void testWithInitialCapacityAndExpansionFactor() {
    
    ResizableDoubleArray eDA3 = new ResizableDoubleArray(3, 3.0f, 3.5f);
    assertEquals("Initial number of elements should be 0", 0, eDA3.getNumElements() );
    
    RandomData randomData = new RandomDataImpl();
    int iterations = randomData.nextInt(100, 3000);
    
    for( int i = 0; i < iterations; i++) {
        eDA3.addElement( i );
    }
    
    assertEquals("Number of elements should be equal to " + iterations, iterations,eDA3.getNumElements());
    
    eDA3.addElement( 2.0 );
    
    assertEquals("Number of elements should be equals to " + (iterations +1),
            iterations +1, eDA3.getNumElements() );
    
    assertEquals("Expansion factor should equal 3.0", 3.0f, eDA3.getExpansionFactor(), Double.MIN_VALUE);
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:22,代码来源:ResizableDoubleArrayTest.java

示例8: testWeightedConsistency

import org.apache.commons.math.random.RandomData; //导入方法依赖的package包/类
/**
 * Tests consistency of weighted statistic computation.
 * For statistics that support weighted evaluation, this test case compares
 * the result of direct computation on an array with repeated values with
 * a weighted computation on the corresponding (shorter) array with each
 * value appearing only once but with a weight value equal to its multiplicity
 * in the repeating array.
 */

public void testWeightedConsistency() throws Exception {

    // See if this statistic computes weighted statistics
    // If not, skip this test
    UnivariateStatistic statistic = getUnivariateStatistic();
    if (!(statistic instanceof WeightedEvaluation)) {
        return;
    }

    // Create arrays of values and corresponding integral weights
    // and longer array with values repeated according to the weights
    final int len = 10;        // length of values array
    final double mu = 0;       // mean of test data
    final double sigma = 5;    // std dev of test data
    double[] values = new double[len];
    double[] weights = new double[len];
    RandomData randomData = new RandomDataImpl();

    // Fill weights array with random int values between 1 and 5
    int[] intWeights = new int[len];
    for (int i = 0; i < len; i++) {
        intWeights[i] = randomData.nextInt(1, 5);
        weights[i] = intWeights[i];
    }

    // Fill values array with random data from N(mu, sigma)
    // and fill valuesList with values from values array with
    // values[i] repeated weights[i] times, each i
    List<Double> valuesList = new ArrayList<Double>();
    for (int i = 0; i < len; i++) {
        double value = randomData.nextGaussian(mu, sigma);
        values[i] = value;
        for (int j = 0; j < intWeights[i]; j++) {
            valuesList.add(new Double(value));
        }
    }

    // Dump valuesList into repeatedValues array
    int sumWeights = valuesList.size();
    double[] repeatedValues = new double[sumWeights];
    for (int i = 0; i < sumWeights; i++) {
        repeatedValues[i] = valuesList.get(i);
    }

    // Compare result of weighted statistic computation with direct computation
    // on array of repeated values
    WeightedEvaluation weightedStatistic = (WeightedEvaluation) statistic;
    TestUtils.assertRelativelyEquals(statistic.evaluate(repeatedValues),
            weightedStatistic.evaluate(values, weights, 0, values.length),
            10E-14);
    
    // Check consistency of weighted evaluation methods
    assertEquals(weightedStatistic.evaluate(values, weights, 0, values.length),
            weightedStatistic.evaluate(values, weights), Double.MIN_VALUE);       

}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:66,代码来源:UnivariateStatisticAbstractTest.java

示例9: testWithInitialCapacityAndExpansionFactor

import org.apache.commons.math.random.RandomData; //导入方法依赖的package包/类
public void testWithInitialCapacityAndExpansionFactor() {

        ResizableDoubleArray eDA3 = new ResizableDoubleArray(3, 3.0f, 3.5f);
        assertEquals("Initial number of elements should be 0", 0, eDA3.getNumElements() );

        RandomData randomData = new RandomDataImpl();
        int iterations = randomData.nextInt(100, 3000);

        for( int i = 0; i < iterations; i++) {
            eDA3.addElement( i );
        }

        assertEquals("Number of elements should be equal to " + iterations, iterations,eDA3.getNumElements());

        eDA3.addElement( 2.0 );

        assertEquals("Number of elements should be equals to " + (iterations +1),
                iterations +1, eDA3.getNumElements() );

        assertEquals("Expansion factor should equal 3.0", 3.0f, eDA3.getExpansionFactor(), Double.MIN_VALUE);
    }
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:22,代码来源:ResizableDoubleArrayTest.java

示例10: testWeightedConsistency

import org.apache.commons.math.random.RandomData; //导入方法依赖的package包/类
/**
 * Tests consistency of weighted statistic computation.
 * For statistics that support weighted evaluation, this test case compares
 * the result of direct computation on an array with repeated values with
 * a weighted computation on the corresponding (shorter) array with each
 * value appearing only once but with a weight value equal to its multiplicity
 * in the repeating array.
 */

public void testWeightedConsistency() throws Exception {

    // See if this statistic computes weighted statistics
    // If not, skip this test
    UnivariateStatistic statistic = getUnivariateStatistic();
    if (!(statistic instanceof WeightedEvaluation)) {
        return;
    }

    // Create arrays of values and corresponding integral weights
    // and longer array with values repeated according to the weights
    final int len = 10;        // length of values array
    final double mu = 0;       // mean of test data
    final double sigma = 5;    // std dev of test data
    double[] values = new double[len];
    double[] weights = new double[len];
    RandomData randomData = new RandomDataImpl();

    // Fill weights array with random int values between 1 and 5
    int[] intWeights = new int[len];
    for (int i = 0; i < len; i++) {
        intWeights[i] = randomData.nextInt(1, 5);
        weights[i] = intWeights[i];
    }

    // Fill values array with random data from N(mu, sigma)
    // and fill valuesList with values from values array with
    // values[i] repeated weights[i] times, each i
    List<Double> valuesList = new ArrayList<Double>();
    for (int i = 0; i < len; i++) {
        double value = randomData.nextGaussian(mu, sigma);
        values[i] = value;
        for (int j = 0; j < intWeights[i]; j++) {
            valuesList.add(new Double(value));
        }
    }

    // Dump valuesList into repeatedValues array
    int sumWeights = valuesList.size();
    double[] repeatedValues = new double[sumWeights];
    for (int i = 0; i < sumWeights; i++) {
        repeatedValues[i] = valuesList.get(i);
    }

    // Compare result of weighted statistic computation with direct computation
    // on array of repeated values
    WeightedEvaluation weightedStatistic = (WeightedEvaluation) statistic;
    TestUtils.assertRelativelyEquals(statistic.evaluate(repeatedValues),
            weightedStatistic.evaluate(values, weights, 0, values.length),
            10E-14);

    // Check consistency of weighted evaluation methods
    assertEquals(weightedStatistic.evaluate(values, weights, 0, values.length),
            weightedStatistic.evaluate(values, weights), Double.MIN_VALUE);

}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:66,代码来源:UnivariateStatisticAbstractTest.java

示例11: testWeightedConsistency

import org.apache.commons.math.random.RandomData; //导入方法依赖的package包/类
/**
 * Tests consistency of weighted statistic computation.
 * For statistics that support weighted evaluation, this test case compares
 * the result of direct computation on an array with repeated values with
 * a weighted computation on the corresponding (shorter) array with each
 * value appearing only once but with a weight value equal to its multiplicity
 * in the repeating array.
 */

@Test
public void testWeightedConsistency() throws Exception {

    // See if this statistic computes weighted statistics
    // If not, skip this test
    UnivariateStatistic statistic = getUnivariateStatistic();
    if (!(statistic instanceof WeightedEvaluation)) {
        return;
    }

    // Create arrays of values and corresponding integral weights
    // and longer array with values repeated according to the weights
    final int len = 10;        // length of values array
    final double mu = 0;       // mean of test data
    final double sigma = 5;    // std dev of test data
    double[] values = new double[len];
    double[] weights = new double[len];
    RandomData randomData = new RandomDataImpl();

    // Fill weights array with random int values between 1 and 5
    int[] intWeights = new int[len];
    for (int i = 0; i < len; i++) {
        intWeights[i] = randomData.nextInt(1, 5);
        weights[i] = intWeights[i];
    }

    // Fill values array with random data from N(mu, sigma)
    // and fill valuesList with values from values array with
    // values[i] repeated weights[i] times, each i
    List<Double> valuesList = new ArrayList<Double>();
    for (int i = 0; i < len; i++) {
        double value = randomData.nextGaussian(mu, sigma);
        values[i] = value;
        for (int j = 0; j < intWeights[i]; j++) {
            valuesList.add(new Double(value));
        }
    }

    // Dump valuesList into repeatedValues array
    int sumWeights = valuesList.size();
    double[] repeatedValues = new double[sumWeights];
    for (int i = 0; i < sumWeights; i++) {
        repeatedValues[i] = valuesList.get(i);
    }

    // Compare result of weighted statistic computation with direct computation
    // on array of repeated values
    WeightedEvaluation weightedStatistic = (WeightedEvaluation) statistic;
    TestUtils.assertRelativelyEquals(statistic.evaluate(repeatedValues),
            weightedStatistic.evaluate(values, weights, 0, values.length),
            10E-14);

    // Check consistency of weighted evaluation methods
    Assert.assertEquals(weightedStatistic.evaluate(values, weights, 0, values.length),
            weightedStatistic.evaluate(values, weights), Double.MIN_VALUE);

}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:67,代码来源:UnivariateStatisticAbstractTest.java

示例12: testWithInitialCapacity

import org.apache.commons.math.random.RandomData; //导入方法依赖的package包/类
public void testWithInitialCapacity() {

        ResizableDoubleArray eDA2 = new ResizableDoubleArray(2);
        assertEquals("Initial number of elements should be 0", 0, eDA2.getNumElements());

        RandomData randomData = new RandomDataImpl();
        int iterations = randomData.nextInt(100, 1000);

        for( int i = 0; i < iterations; i++) {
            eDA2.addElement( i );
        }

        assertEquals("Number of elements should be equal to " + iterations, iterations, eDA2.getNumElements());

        eDA2.addElement( 2.0 );

        assertEquals("Number of elements should be equals to " + (iterations +1),
                iterations + 1 , eDA2.getNumElements() );
    }
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:20,代码来源:ResizableDoubleArrayTest.java


注:本文中的org.apache.commons.math.random.RandomData.nextInt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。