本文整理了Java中java.util.Random.nextFloat()
方法的一些代码示例,展示了Random.nextFloat()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Random.nextFloat()
方法的具体详情如下:
包路径:java.util.Random
类名称:Random
方法名:nextFloat
[英]Returns a pseudo-random uniformly distributed floatin the half-open range [0.0, 1.0).
[中]返回半开范围[0.0,1.0]内的伪随机均匀分布浮点值。
代码示例来源:origin: stanfordnlp/CoreNLP
public ConcatVectorConstructionRecord(Random r, int[] sizes) {
int length = sizes.length;
componentSizes = sizes;
densePieces = new double[length][];
sparseOffsets = new int[length];
sparseValues = new double[length];
for (int i = 0; i < length; i++) {
boolean sparse = componentSizes[i] == -1;
if (sparse) {
sparseOffsets[i] = r.nextInt(100);
sparseValues[i] = r.nextFloat();
} else {
densePieces[i] = new double[componentSizes[i]];
for (int j = 0; j < densePieces[i].length; j++) {
densePieces[i][j] = r.nextFloat();
}
}
}
}
代码示例来源:origin: stackoverflow.com
float minX = 50.0f;
float maxX = 100.0f;
Random rand = new Random();
float finalX = rand.nextFloat() * (maxX - minX) + minX;
代码示例来源:origin: apache/incubator-pinot
@Override
public void init() {
final Random rand = new Random(System.currentTimeMillis());
final int start = rand.nextInt(cardinality);
final int end = start + cardinality;
for (int i = start; i < end; i++) {
case LONG:
longValues = new ArrayList<Long>();
final long longStart = rand.nextInt(cardinality);
final long longEnd = longStart + cardinality;
for (long i = longStart; i < longEnd; i++) {
case FLOAT:
floatValues = new ArrayList<Float>();
final float floatStart = rand.nextFloat() * rand.nextInt(1000);
int floatCounter = 1;
while (true) {
代码示例来源:origin: apache/flink
@Override
protected TestUserClassBase[] getTestData() {
Random rnd = new Random(874597969123412341L);
return new TestUserClassBase[]{
new TestUserClass1(rnd.nextInt(), "foo", rnd.nextLong()),
new TestUserClass2(rnd.nextInt(), "bar", rnd.nextFloat()),
new TestUserClass3(rnd.nextInt(), "bar", rnd.nextFloat())
};
}
代码示例来源:origin: apache/hbase
/**
* From a list of regions pick a random one. Null can be returned which
* {@link StochasticLoadBalancer#balanceCluster(Map)} recognize as signal to try a region move
* rather than swap.
*
* @param cluster The state of the cluster
* @param server index of the server
* @param chanceOfNoSwap Chance that this will decide to try a move rather
* than a swap.
* @return a random {@link RegionInfo} or null if an asymmetrical move is
* suggested.
*/
protected int pickRandomRegion(Cluster cluster, int server, double chanceOfNoSwap) {
// Check to see if this is just a move.
if (cluster.regionsPerServer[server].length == 0 || RANDOM.nextFloat() < chanceOfNoSwap) {
// signal a move only.
return -1;
}
int rand = RANDOM.nextInt(cluster.regionsPerServer[server].length);
return cluster.regionsPerServer[server][rand];
}
protected int pickRandomServer(Cluster cluster) {
代码示例来源:origin: Dreampie/Resty
protected void transform(int x, int y, double[] t) {
Random r = new Random();
int angle = (int) (r.nextFloat() * 255);
t[0] = x + tx[angle];
t[1] = y + ty[angle];
}
代码示例来源:origin: apache/flink
@Override
protected TestUserInterface[] getTestData() {
Random rnd = new Random(874597969123412341L);
return new TestUserInterface[]{
new TestUserClass1(rnd.nextInt(), "foo", rnd.nextLong()),
new TestUserClass2(rnd.nextInt(), "bar", rnd.nextFloat())
};
}
代码示例来源:origin: GlowstoneMC/Glowstone
private static int calculateRandomizedModifier(Random random, ItemStack itemStack, int cost) {
int modifier = calculateModifier(itemStack);
if (modifier <= 0) {
return -1;
}
modifier /= 4;
modifier += 1;
modifier = random.nextInt(modifier) + random.nextInt(modifier);
modifier += 1 + cost;
float randomValue = 1 + (random.nextFloat() + random.nextFloat() - 1.0F) * 0.15F;
modifier = Math.round(modifier * randomValue);
modifier = Math.max(1, modifier);
return modifier;
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
public static Vector3f[] getPositions(int count, long seed) {
Random rnd = new Random(seed);
Vector3f[] vectors = new Vector3f[count];
for (int i = 0; i < count; i++) {
vectors[i] = new Vector3f((rnd.nextFloat() - 0.5f) * poiRadius,
(rnd.nextFloat() - 0.5f) * poiRadius,
(rnd.nextFloat() - 0.5f) * poiRadius);
}
return vectors;
}
代码示例来源:origin: spring-projects/spring-integration-samples
/**
* @param loanRequest the loan request
* @return a LoanQuote for the given request
*/
public LoanQuote quote(LoanRequest loanRequest) {
Calendar calendar = Calendar.getInstance();
LoanQuote loanQuote = new LoanQuote();
Random random = new Random();
loanQuote.setQuoteDate(calendar.getTime());
calendar.add(Calendar.DAY_OF_YEAR, random.nextInt(25));
loanQuote.setExpirationDate(calendar.getTime());
loanQuote.setRate(random.nextFloat() + this.baseRate);
loanQuote.setTerm(10 + random.nextInt(10));
loanQuote.setAmount(250000 + random.nextInt(40000));
loanQuote.setLender(this.name);
return loanQuote;
}
代码示例来源:origin: dinuscxj/LoadingDrawable
private void initWaterDropHolders(RectF bottleRect, RectF waterRect) {
float bottleRadius = bottleRect.width() / 2.0f;
float lowestWaterPointY = waterRect.top;
float twoSidesInterval = 0.2f * bottleRect.width();
float atLeastDelayDuration = 0.1f;
float unitDuration = 0.1f;
float delayDurationRange = 0.6f;
int radiusRandomRange = MAX_WATER_DROP_RADIUS - MIN_WATER_DROP_RADIUS;
float currentXRandomRange = bottleRect.width() * 0.6f;
for (int i = 0; i < DEFAULT_WATER_DROP_COUNT; i++) {
WaterDropHolder waterDropHolder = new WaterDropHolder();
waterDropHolder.mRadius = MIN_WATER_DROP_RADIUS + mRandom.nextInt(radiusRandomRange);
waterDropHolder.mInitX = bottleRect.left + twoSidesInterval + mRandom.nextFloat() * currentXRandomRange;
waterDropHolder.mInitY = lowestWaterPointY + waterDropHolder.mRadius / 2.0f;
waterDropHolder.mRiseHeight = getMaxRiseHeight(bottleRadius, waterDropHolder.mRadius, waterDropHolder.mInitX - bottleRect.left)
* (0.2f + 0.8f * mRandom.nextFloat());
waterDropHolder.mDelayDuration = atLeastDelayDuration + mRandom.nextFloat() * delayDurationRange;
waterDropHolder.mDuration = waterDropHolder.mRiseHeight / bottleRadius * unitDuration;
mWaterDropHolders.add(waterDropHolder);
}
}
代码示例来源:origin: ankidroid/Anki-Android
/**
* Return a random float within the range of min and max.
*/
public static float randomFloatInRange(float min, float max) {
Random rand = new Random();
return rand.nextFloat() * (max - min) + min;
}
}
代码示例来源:origin: apache/kafka
Random random = new Random();
start = System.nanoTime();
for (int i = 0; i < iters; i++) {
n += random.nextInt();
floats[i] = random.nextFloat();
Arrays.sort(floats);
代码示例来源:origin: ivan-vasilev/neuralnetworks
int b = rand.nextInt(256);
int g = rand.nextInt(256);
int r = rand.nextInt(256);
im.setRGB(j, k, (b << 16) | (g << 8) | r);
for (int j = 0; j < targetDimensions; j++)
nextTarget[j] = rand.nextFloat();
代码示例来源:origin: JorgeCastilloPrz/AndroidFillableLoaders
private float nextFloat(float upperBound) {
Random random = new Random();
return (Math.abs(random.nextFloat()) % (upperBound + 1));
}
}
代码示例来源:origin: apache/incubator-pinot
private List<GenericRow> createTestDataWithTimespec(TimeFieldSpec timeFieldSpec) {
List<GenericRow> rows = new ArrayList<>();
Random random = new Random();
Map<String, Object> fields;
for (int i = 0; i < NUM_ROWS; i++) {
fields = new HashMap<>();
fields.put(D1, RandomStringUtils.randomAlphabetic(2));
fields.put(D2, RandomStringUtils.randomAlphabetic(5));
fields.put(M1, Math.abs(random.nextInt()));
fields.put(M2, Math.abs(random.nextFloat()));
long timestamp = System.currentTimeMillis();
Object timeColumnValue = timeFieldSpec.getIncomingGranularitySpec().fromMillis(timestamp);
fields.put(timeFieldSpec.getName(), timeColumnValue);
GenericRow row = new GenericRow();
row.init(fields);
rows.add(row);
}
return rows;
}
代码示例来源:origin: robinhood/ticker
@Override
protected void onUpdate() {
final int digits = RANDOM.nextInt(2) + 6;
ticker1.setText(getRandomNumber(digits));
final String currencyFloat = Float.toString(RANDOM.nextFloat() * 100);
ticker2.setText("$" + currencyFloat.substring(0, Math.min(digits, currencyFloat.length())));
ticker3.setText(generateChars(RANDOM, alphabetlist, digits));
}
代码示例来源:origin: ankidroid/Anki-Android
public HttpSyncer(String hkey, Connection con) {
mHKey = hkey;
mSKey = Utils.checksum(Float.toString(new Random().nextFloat())).substring(0, 8);
mCon = con;
mPostVars = new HashMap<>();
}
代码示例来源:origin: davemorrissey/subsampling-scale-image-view
private void play() {
Random random = new Random();
if (view.isReady()) {
float maxScale = view.getMaxScale();
float minScale = view.getMinScale();
float scale = (random.nextFloat() * (maxScale - minScale)) + minScale;
PointF center = new PointF(random.nextInt(view.getSWidth()), random.nextInt(view.getSHeight()));
view.setPin(center);
AnimationBuilder animationBuilder = view.animateScaleAndCenter(scale, center);
if (getPage() == 3) {
animationBuilder.withDuration(2000).withEasing(EASE_OUT_QUAD).withInterruptible(false).start();
} else {
animationBuilder.withDuration(750).start();
}
}
}
代码示例来源:origin: facebook/facebook-android-sdk
private static void putFloatArray(String key, Bundle bundle) {
int length = random.nextInt(50);
float[] array = new float[length];
for (int i = 0; i < length; i++) {
array[i] = random.nextFloat();
}
bundle.putFloatArray(key, array);
}
内容来源于网络,如有侵权,请联系作者删除!