本文整理匯總了Java中java.util.Random.nextDouble方法的典型用法代碼示例。如果您正苦於以下問題:Java Random.nextDouble方法的具體用法?Java Random.nextDouble怎麽用?Java Random.nextDouble使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.Random
的用法示例。
在下文中一共展示了Random.nextDouble方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: generate
import java.util.Random; //導入方法依賴的package包/類
@Override
public List<CpuResource> generate(ArrayList<Object> parameters) {
ArrayList<CpuResource> resList = new ArrayList<CpuResource>();
NetworkStack ns = (NetworkStack)parameters.get(0);
Integer minCPU = ConversionHelper.paramObjectToInteger(parameters.get(1));
Integer maxCPU = ConversionHelper.paramObjectToInteger(parameters.get(2));
Random random = new Random();
SubstrateNetwork sn = ns.getSubstrate();
for(SubstrateNode n : sn.getVertices()) {
CpuResource cpu = new CpuResource(n);
int value = (int) (minCPU + (maxCPU
- minCPU + 1)
* random.nextDouble());
cpu.setCycles((double) value);
n.add(cpu);
resList.add(cpu);
}
return resList;
}
示例2: testMiddleDateBatchPutDataCallback
import java.util.Random; //導入方法依賴的package包/類
@Ignore
@Test
public void testMiddleDateBatchPutDataCallback() {
Random random = new Random();
int time = getTime();
for(int i = 0;i<5500;i++) {
double nextDouble = random.nextDouble() * 100;
Point point = Point.metric("test1")
.tag("tagk1", "tagv1")
.tag("tagk2", "tagv2")
.tag("tagk3", "tagv3")
.timestamp(time + i).value(nextDouble)
.build();
tsdb.put(point);
}
}
示例3: test_for_issue
import java.util.Random; //導入方法依賴的package包/類
public void test_for_issue() throws Exception {
double[] values = new double[128];
Random random = new Random();
for (int i = 0; i < values.length; ++i) {
values[i] = random.nextDouble();
}
Map<String, double[]> map = new HashMap<String, double[]>();
map.put("val", values);
String text = JSON.toJSONString(map);
System.out.println(text);
Map<String, double[]> map2 = JSON.parseObject(text, new TypeReference<HashMap<String, double[]>>() {});
double[] values2 = (double[]) map2.get("val");
Assert.assertTrue(Arrays.equals(values2, values));
}
示例4: generateColorScale
import java.util.Random; //導入方法依賴的package包/類
public static String[] generateColorScale(int n) {
if (n <= 0) {
throw new IllegalArgumentException("Color scale size has to be stricly positive");
}
String[] colors = new String[n];
Random random = new Random();
for (int i = 0; i < n; i++) {
double h = random.nextDouble();
h += GOLDEN_RATIO_CONJUGATE;
h %= 1;
long[] rgb = hsvToRgb(h, 0.5, 0.95);
String hex = String.format("#%02x%02x%02x", rgb[0], rgb[1], rgb[2]).toUpperCase();
colors[i] = hex;
}
return colors;
}
示例5: PlanetData
import java.util.Random; //導入方法依賴的package包/類
public PlanetData(long seed, StarData data) {
this.seed = seed;
this.star = data;
plRandom = new Random(seed);
chRandom = new Random();
name = generateName(plRandom);
albedo = plRandom.nextDouble();
distanceToStar = /*
* (Maths.normalStandardDistribution((random.nextDouble() + 0) * 6)) *
* (MAXDISSTAR - MINDISSTAR) + MINDISSTAR;
*/ MINDISSTAR + plRandom.nextDouble() * (MAXDISSTAR - MINDISSTAR);
radiusMax = (long) (Maths.normalStandardDistribution(plRandom.nextDouble() * 2) * MAX_RADIUS);
radiusFade = radiusMax - (long) Math.min(Math.max(0, plRandom.nextInt(40) + 10), radiusMax * 0.1);
daytimePercentage = (float) (plRandom.nextDouble() * 0.6 + 0.2);
avgLengthOfDay = MINDAYSEC + plRandom.nextInt(MAXDAYSEC - MINDAYSEC);
timeOffset = plRandom.nextInt(avgLengthOfDay);
avgTempKelvin = calculateAvgPlanetTemp(star.getLuminosity(), albedo, distanceToStar, daytimePercentage)
+ (plRandom.nextDouble() * 0.2 + 0.9) * TEMPOFFSET;
maxTempDifKelvin = MINTEMPDIF
+ Maths.normalStandardDistribution((1 - plRandom.nextDouble()) * 7) * (MAXTEMPDIF - MINTEMPDIF);
humidity = plRandom.nextDouble();
maxDifHumidity = plRandom.nextDouble();
tempNoise = new NoiseWrapper(new OpenSimplexNoise(seed ^ (long) avgTempKelvin)).setXScale(1 / 300.0)
.setYScale(1 / 300.0);
heightsNoise = new NoiseWrapper(new OpenSimplexNoise(seed ^ 0)).setXScale(1 / 100.0).setYScale(1 / 100.0);
humidityNoise = new NoiseWrapper(new OpenSimplexNoise(seed ^ (long) humidity)).setXScale(1 / 200.0)
.setYScale(1 / 200.0);
}
示例6: run
import java.util.Random; //導入方法依賴的package包/類
@Override
public void run() {
try {
Stock[] stocks = new Stock[] { new Stock("GOOG", 435.43),
new Stock("YHOO", 27.88), new Stock("ASF", 1015.55), };
Random r = new Random(System.currentTimeMillis());
while (run) {
for (int j = 0; j < 1; j++) {
int i = r.nextInt() % 3;
if (i < 0)
i = i * (-1);
Stock stock = stocks[i];
double change = r.nextDouble();
boolean plus = r.nextBoolean();
if (plus) {
stock.setValue(stock.getValue() + change);
} else {
stock.setValue(stock.getValue() - change);
}
stock.setCnt(++ticknr);
for (TickListener l : listeners) {
l.tick(stock);
}
}
Thread.sleep(850);
}
} catch (InterruptedException ix) {
// Ignore
} catch (Exception x) {
x.printStackTrace();
}
}
示例7: randomDoubleVector
import java.util.Random; //導入方法依賴的package包/類
/** Returns a random vector of given size, using the provided {@link java.util.Random} object.
*
* @param n the vector size.
* @param random the random number generator to be used (its {@link Random#nextDouble()} method will be called).
*/
public static double[] randomDoubleVector(final int n, final Random random) {
double[] a = new double[n];
for (int i = 0; i < n; i++)
a[i] = random.nextDouble();
return a;
}
示例8: getRandom
import java.util.Random; //導入方法依賴的package包/類
@Override
public Vector getRandom(Random random) {
final BlockVector randomBlock = positions.chooseRandom(random);
double dx = random.nextDouble();
double dy = random.nextDouble();
double dz = random.nextDouble();
return randomBlock.add(dx, dy, dz);
}
示例9: getRandom
import java.util.Random; //導入方法依賴的package包/類
/**
* Create a random vector with a magnitude no greater than specified
* @param rand The source of randomness to use.
* @param maxMagnitude
* @return A new random Vector2D
*/
public static Vector2D getRandom(Random rand, double maxMagnitude) {
final double max = maxMagnitude * maxMagnitude;
final double x2 = rand.nextDouble() * max;
final double y2 = rand.nextDouble() * (max - x2);
final double x = rand.nextBoolean() ? (double)Math.sqrt(x2) : -(double)Math.sqrt(x2);
final double y = rand.nextBoolean() ? (double)Math.sqrt(y2) : -(double)Math.sqrt(y2);
return new Vector2D(x, y);
}
示例10: new_bell
import java.util.Random; //導入方法依賴的package包/類
public static SF2Layer new_bell(SF2Soundbank sf2) {
Random random = new Random(102030201);
int x = 8;
int fftsize = 4096 * x;
double[] data = new double[fftsize * 2];
double base = x * 25;
double start_w = 0.01;
double end_w = 0.05;
double start_a = 0.2;
double end_a = 0.00001;
double a = start_a;
double a_step = Math.pow(end_a / start_a, 1.0 / 40.0);
for (int i = 0; i < 40; i++) {
double detune = 1 + (random.nextDouble() * 2 - 1) * 0.01;
double w = start_w + (end_w - start_w) * (i / 40.0);
complexGaussianDist(data, base * (i + 1) * detune, w, a);
a *= a_step;
}
SF2Sample sample = newSimpleFFTSample(sf2, "EPiano", data, base);
SF2Layer layer = newLayer(sf2, "EPiano", sample);
SF2Region region = layer.getRegions().get(0);
region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
region.putInteger(SF2Region.GENERATOR_ATTACKVOLENV, -12000);
region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 0);
region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 4000);
region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, 1000);
region.putInteger(SF2Region.GENERATOR_ATTACKMODENV, 1200);
region.putInteger(SF2Region.GENERATOR_RELEASEMODENV, 12000);
region.putInteger(SF2Region.GENERATOR_MODENVTOFILTERFC, -9000);
region.putInteger(SF2Region.GENERATOR_INITIALFILTERFC, 16000);
return layer;
}
示例11: randomChar
import java.util.Random; //導入方法依賴的package包/類
public char randomChar(Random random) {
double r = random.nextDouble() * ratioSum;
for (int i = 0; i < randomCharDescriptors.length; i++) {
RandomCharDescriptor descriptor = randomCharDescriptors[i];
if ((r -= descriptor.ratio()) < 0) {
return descriptor.randomChar(random);
}
}
// Internal error - randomCharAvailable() needs to be checked
throw new IllegalStateException("No random char descriptions available");
}
示例12: testPrefixesDeep
import java.util.Random; //導入方法依賴的package包/類
@Test
public void testPrefixesDeep() {
Set<String> inset = new ObjectOpenHashSet<>();
Set<String> pfset = new ObjectOpenHashSet<>();
Random rand = new Random(0);
for (int i = 100; i < 999; i++) {
if (rand.nextDouble() < 0.3) {
String commonPref = String.valueOf(i);
boolean putPrefix = rand.nextDouble() < 0.9;
if (putPrefix) {
pfset.add(commonPref);
inset.add(commonPref);
}
for (int j = 100; j < 450; j++) {
if (rand.nextDouble() < 0.3) {
inset.add(commonPref + j);
if (! putPrefix) pfset.add(commonPref + j);
}
}
}
}
char[][] resultArray = URLRespectsRobots.toSortedPrefixFreeCharArrays(inset);
Set<String> result = new ObjectOpenHashSet<>();
for (char[] a: resultArray) result.add(new String(a));
assertEquals(result, pfset);
}
示例13: getStartPosition
import java.util.Random; //導入方法依賴的package包/類
private static void getStartPosition(double[] position, Test tester) {
Random randP = new Random();
Point2D p = new Point2D.Double(randP.nextDouble(), randP.nextDouble());
List<Obstacle> obs = tester.ps.obstacles;
while (containPoint(obs, p)) {
p = new Point2D.Double(randP.nextDouble(), randP.nextDouble());
}
position[0] = p.getX();
position[1] = p.getY();
}
示例14: new_open_hihat
import java.util.Random; //導入方法依賴的package包/類
public static SF2Layer new_open_hihat(SF2Soundbank sf2) {
double datah[];
{
int fftlen = 4096 * 4;
double[] data = new double[2 * fftlen];
Random random = new Random(3049912);
for (int i = 0; i < data.length; i += 2)
data[i] = (2.0 * (random.nextDouble() - 0.5));
for (int i = fftlen / 2; i < data.length; i++)
data[i] = 0;
for (int i = 0; i < 200; i++)
data[i] = 0;
for (int i = 0; i < 2048 * 4; i++) {
double gain = (i / (2048.0 * 4.0));
data[i] = gain;
}
datah = data;
}
SF2Sample sample = newSimpleFFTSample(sf2, "Open Hi-Hat", datah, 1000, 5);
SF2Layer layer = new SF2Layer(sf2);
layer.setName("Open Hi-Hat");
SF2GlobalRegion global = new SF2GlobalRegion();
layer.setGlobalZone(global);
sf2.addResource(layer);
SF2LayerRegion region = new SF2LayerRegion();
region.putInteger(SF2Region.GENERATOR_DECAYVOLENV, 1500);
region.putInteger(SF2Region.GENERATOR_SAMPLEMODES, 1);
region.putInteger(SF2Region.GENERATOR_RELEASEVOLENV, 1500);
region.putInteger(SF2Region.GENERATOR_SUSTAINVOLENV, 1000);
region.putInteger(SF2Region.GENERATOR_SCALETUNING, 0);
region.putInteger(SF2Region.GENERATOR_EXCLUSIVECLASS, 1);
region.setSample(sample);
layer.getRegions().add(region);
return layer;
}
示例15: testLitterDateBatchPutDataCallback
import java.util.Random; //導入方法依賴的package包/類
@Test
public void testLitterDateBatchPutDataCallback() {
Random random = new Random();
int time = getTime();
for(int i = 0;i<4000;i++) {
double nextDouble = random.nextDouble() * 100;
Point point = Point.metric("test1")
.tag("tagk1", "tagv1")
.tag("tagk2", "tagv2")
.tag("tagk3", "tagv3")
.timestamp(time + i).value(nextDouble)
.build();
tsdb.put(point);
}
}