本文整理匯總了Java中org.apache.commons.math3.random.RandomDataGenerator.nextInt方法的典型用法代碼示例。如果您正苦於以下問題:Java RandomDataGenerator.nextInt方法的具體用法?Java RandomDataGenerator.nextInt怎麽用?Java RandomDataGenerator.nextInt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.math3.random.RandomDataGenerator
的用法示例。
在下文中一共展示了RandomDataGenerator.nextInt方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createSpots
import org.apache.commons.math3.random.RandomDataGenerator; //導入方法依賴的package包/類
private static float[] createSpots(int size, int n, int min, int max, double sigmaX, double sigmaY)
{
float[] data = new float[size * size];
// Randomly put on spots
RandomDataGenerator rg = new RandomDataGenerator(rand);
while (n-- > 0)
{
data[rand.nextInt(data.length)] = rg.nextInt(min, max);
}
// Blur
FloatProcessor fp = new FloatProcessor(size, size, data);
GaussianBlur gb = new GaussianBlur();
gb.blurFloat(fp, sigmaX, sigmaY, 0.0002);
return (float[]) fp.getPixels();
}
示例2: createSpots3D
import org.apache.commons.math3.random.RandomDataGenerator; //導入方法依賴的package包/類
private static float[][] createSpots3D(int size, int z, int n, int min, int max, double sigmaX, double sigmaY)
{
float[] data = new float[size * size];
// Randomly put on spots
RandomDataGenerator rg = new RandomDataGenerator(rand);
while (n-- > 0)
{
data[rand.nextInt(data.length)] = rg.nextInt(min, max);
}
int middle = z / 2;
float[][] result = new float[z][];
for (int i = 0; i < z; i++)
{
FloatProcessor fp = new FloatProcessor(size, size, data.clone());
GaussianBlur gb = new GaussianBlur();
// Increase blur when out-of-focus
double scale = createWidthScale(Math.abs(middle - i), middle);
gb.blurFloat(fp, sigmaX * scale, sigmaY * scale, 0.0002);
result[i] = (float[]) fp.getPixels();
}
return result;
}
示例3: getRandomValue
import org.apache.commons.math3.random.RandomDataGenerator; //導入方法依賴的package包/類
/**
* @param rdg random number generator to use
* @return a hyperparameter value chosen uniformly at random from the range
*/
@Override
public Integer getRandomValue(RandomDataGenerator rdg) {
if (max == min) {
return min;
}
return rdg.nextInt(min, max);
}
示例4: moveCellsWithOffset
import org.apache.commons.math3.random.RandomDataGenerator; //導入方法依賴的package包/類
public void moveCellsWithOffset(Array<? extends Rectangle> cells, int x, int y, int offsetX, int offsetY) {
Gdx.app.log("RectanglesSeparator", "Moving cells to (" + x + ", " + y + ")");
RandomDataGenerator randomDataGenerator = new RandomDataGenerator();
for (Rectangle cell : cells) {
if (!(cell instanceof GameRoom)) {
// X/Y +- 1 so they are not stacked at the exact same spot and can't separate
int newX = randomDataGenerator.nextInt(x - offsetX, x + offsetX);
int newY = randomDataGenerator.nextInt(y - offsetY, y + offsetY);
cell.setCenter(new Vector2(newX, newY));
}
}
}
示例5: getRandomInt
import org.apache.commons.math3.random.RandomDataGenerator; //導入方法依賴的package包/類
private int getRandomInt(int lower, int upper) {
RandomDataGenerator randomDataGenerator = new RandomDataGenerator();
if (upper < lower) {
upper = lower;
}
return randomDataGenerator.nextInt(lower, upper);
}
示例6: generate
import org.apache.commons.math3.random.RandomDataGenerator; //導入方法依賴的package包/類
public void generate(int sleep_frequency) throws InterruptedException {
RandomDataGenerator messageGenerator = new RandomDataGenerator();
long time = System.currentTimeMillis();
ThroughputLog throughput = new ThroughputLog(this.getClass().getSimpleName());
// for loop to generate message
for (long sent_sentences = 0; sent_sentences < SENTENCE_NUM; ++sent_sentences) {
double sentence_length = messageGenerator.nextGaussian(mu, sigma);
StringBuilder messageBuilder = new StringBuilder();
for (int l = 0; l < sentence_length; ++l) {
int number = messageGenerator.nextInt(1, uniformSize);
messageBuilder.append(Utils.intToString(number)).append(" ");
}
// Add timestamp
messageBuilder.append(Constant.TimeSeparator).append(System.currentTimeMillis());
throughput.execute();
ProducerRecord<String, String> newRecord = new ProducerRecord<>(TOPIC, messageBuilder.toString());
producer.send(newRecord);
// control data generate speed
if (sleep_frequency > 0 && sent_sentences % sleep_frequency == 0) {
Thread.sleep(1);
}
}
producer.close();
logger.info("LatencyLog: " + String.valueOf(System.currentTimeMillis() - time));
}
示例7: initRows
import org.apache.commons.math3.random.RandomDataGenerator; //導入方法依賴的package包/類
private void initRows() {
rows.clear();
final RandomDataGenerator rng = new RandomDataGenerator();
final List<Pupil> pupils = new ArrayList<Pupil>(Arrays.asList(Pupil.values()));
while (!pupils.isEmpty()) {
final int index;
if (pupils.size() > 1) {
index = rng.nextInt(0, pupils.size() - 1);
} else {
index = 0;
}
final Pupil pupil = pupils.remove(index);
rows.add(new DashboardRow(pupil));
}
}
示例8: nextUnlabeled
import org.apache.commons.math3.random.RandomDataGenerator; //導入方法依賴的package包/類
private int nextUnlabeled( ){
RandomDataGenerator rand = new RandomDataGenerator();
int start = rand.nextInt(0, edgels.size()-1);
for ( int i=start; i<edgels.size(); i++){
if( labelMems[i] == 0 ) return i;
}
return -1;
}
示例9: uniform
import org.apache.commons.math3.random.RandomDataGenerator; //導入方法依賴的package包/類
@Override
public Integer uniform( RandomDataGenerator random, Integer min, Integer max )
{
if ( min == max )
{
return min;
}
return random.nextInt( min, max );
}
示例10: nextInt
import org.apache.commons.math3.random.RandomDataGenerator; //導入方法依賴的package包/類
/** Same as random.nextInt(lower, upper), but does not throw exception when lower == upper */
public static int nextInt(int lower, int upper, RandomDataGenerator random) {
return lower == upper ? lower : random.nextInt(lower, upper);
}
示例11: jTransforms2DDHTIsFasterThanFHT2
import org.apache.commons.math3.random.RandomDataGenerator; //導入方法依賴的package包/類
@Test
public void jTransforms2DDHTIsFasterThanFHT2()
{
// Test the forward DHT of data. and reverse transform or the pre-computed correlation.
int size = 256;
int w = size / 4;
RandomGenerator r = new Well19937c(30051977);
RandomDataGenerator rdg = new RandomDataGenerator(r);
// Blob in the centre
FloatProcessor fp = createProcessor(size, size / 2 - w / 2, size / 2 - w / 2, w, w, null);
FHT2 fht2 = new FHT2((float[]) fp.getPixels(), size, false);
fht2.transform();
fht2.initialiseFastMultiply();
// Random blobs, original and correlated
int N = 40;
float[][] data = new float[N * 2][];
int lower = w;
int upper = size - w;
for (int i = 0, j = 0; i < N; i++)
{
int x = rdg.nextInt(lower, upper);
int y = rdg.nextInt(lower, upper);
fp = createProcessor(size, x, y, w, w, r);
float[] pixels = (float[]) fp.getPixels();
data[j++] = pixels.clone();
FHT2 fht1 = new FHT2(pixels, size, false);
fht1.copyTables(fht2);
fht2.transform();
float[] pixels2 = new float[pixels.length];
fht2.conjugateMultiply(fht2, pixels2);
data[j++] = pixels2;
}
//CommonUtils.setThreadsBeginN_1D_FFT_2Threads(Long.MAX_VALUE);
//CommonUtils.setThreadsBeginN_1D_FFT_4Threads(Long.MAX_VALUE);
CommonUtils.setThreadsBeginN_2D(Long.MAX_VALUE);
TimingService ts = new TimingService();
ts.execute(new IJFHTSpeedTask(size, data));
ts.execute(new IJFHT2SpeedTask(size, data));
ts.execute(new JTransformsDHTSpeedTask(size, data));
ts.repeat();
ts.report();
Assert.assertTrue(ts.get(-1).getMean() < ts.get(-2).getMean());
}