本文整理匯總了Java中org.apache.commons.lang.math.RandomUtils.nextFloat方法的典型用法代碼示例。如果您正苦於以下問題:Java RandomUtils.nextFloat方法的具體用法?Java RandomUtils.nextFloat怎麽用?Java RandomUtils.nextFloat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.lang.math.RandomUtils
的用法示例。
在下文中一共展示了RandomUtils.nextFloat方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testWritePerformance
import org.apache.commons.lang.math.RandomUtils; //導入方法依賴的package包/類
@Test
public void testWritePerformance() throws Exception {
System.out.println("Writing " + NumberFormat.getInstance().format(MAX_DOCS) + " values.");
System.out.println("Float array bytes: " + NumberFormat.getInstance().format(RamUsageEstimator.sizeOf(new float[MAX_DOCS])));
OffsetGrowableFloatWriter writer = new OffsetGrowableFloatWriter(OffsetGrowableFloatWriter.DEFAULT_PRECISION, 2, MAX_DOCS, PackedInts.DEFAULT);
long start = System.currentTimeMillis();
for (int i = 0; i < MAX_DOCS; i++) {
float value = RandomUtils.nextFloat() * RandomUtils.nextFloat();
int j = RandomUtils.nextInt(MAX_DOCS);
writer.setFloat(j, value);
assertEquals(value, writer.getFloat(j), OffsetGrowableFloatWriter.DEFAULT_PRECISION);
}
System.out.println("OffsetGrowableFloatWriter bytes: " + NumberFormat.getInstance().format(writer.ramBytesUsed()) + " in " + (System.currentTimeMillis() - start) + "ms ...");
}
示例2: selectRandomItems
import org.apache.commons.lang.math.RandomUtils; //導入方法依賴的package包/類
/** Selects and returns ceil(ratio * items.length) random items from the given array */
public static <T> List<T> selectRandomItems(T[] items, float ratio) {
int remaining = (int)Math.ceil(items.length * ratio);
List<T> selectedItems = new ArrayList<T>(remaining);
for (int i=0; i<items.length && remaining > 0; i++) {
if (RandomUtils.nextFloat() < ((float)remaining/(items.length-i))) {
selectedItems.add(items[i]);
remaining--;
}
}
return selectedItems;
}
示例3: onQQGroupMessage
import org.apache.commons.lang.math.RandomUtils; //導入方法依賴的package包/類
private void onQQGroupMessage(final GroupMessage message) {
final long groupId = message.getGroupId();
final String content = message.getContent();
final String userName = Long.toHexString(message.getUserId());
// Push to third system
String qqMsg = content.replaceAll("\\[\"face\",[0-9]+\\]", "");
if (StringUtils.isNotBlank(qqMsg)) {
qqMsg = "<p>" + qqMsg + "</p>";
sendToThird(qqMsg, userName);
}
String msg = "";
if (StringUtils.contains(content, XiaoVs.QQ_BOT_NAME)
|| (StringUtils.length(content) > 6
&& (StringUtils.contains(content, "?") || StringUtils.contains(content, "?") || StringUtils.contains(content, "問")))) {
msg = answer(content, userName);
}
if (StringUtils.isBlank(msg)) {
return;
}
if (RandomUtils.nextFloat() >= 0.9) {
Long latestAdTime = GROUP_AD_TIME.get(groupId);
if (null == latestAdTime) {
latestAdTime = 0L;
}
final long now = System.currentTimeMillis();
if (now - latestAdTime > 1000 * 60 * 30) {
msg = msg + "。\n" + ADS.get(RandomUtils.nextInt(ADS.size()));
GROUP_AD_TIME.put(groupId, now);
}
}
sendMessageToGroup(groupId, msg);
}
示例4: onQQDiscussMessage
import org.apache.commons.lang.math.RandomUtils; //導入方法依賴的package包/類
private void onQQDiscussMessage(final DiscussMessage message) {
final long discussId = message.getDiscussId();
final String content = message.getContent();
final String userName = Long.toHexString(message.getUserId());
// Push to third system
String qqMsg = content.replaceAll("\\[\"face\",[0-9]+\\]", "");
if (StringUtils.isNotBlank(qqMsg)) {
qqMsg = "<p>" + qqMsg + "</p>";
sendToThird(qqMsg, userName);
}
String msg = "";
if (StringUtils.contains(content, XiaoVs.QQ_BOT_NAME)
|| (StringUtils.length(content) > 6
&& (StringUtils.contains(content, "?") || StringUtils.contains(content, "?") || StringUtils.contains(content, "問")))) {
msg = answer(content, userName);
}
if (StringUtils.isBlank(msg)) {
return;
}
if (RandomUtils.nextFloat() >= 0.9) {
Long latestAdTime = DISCUSS_AD_TIME.get(discussId);
if (null == latestAdTime) {
latestAdTime = 0L;
}
final long now = System.currentTimeMillis();
if (now - latestAdTime > 1000 * 60 * 30) {
msg = msg + "。\n" + ADS.get(RandomUtils.nextInt(ADS.size()));
DISCUSS_AD_TIME.put(discussId, now);
}
}
sendMessageToDiscuss(discussId, msg);
}
示例5: createParam
import org.apache.commons.lang.math.RandomUtils; //導入方法依賴的package包/類
private Object createParam(Class type) throws IllegalAccessException, InvocationTargetException,
InstantiationException {
Object param;
if (type == String.class) {
param = "test";
} else if (type == Integer.class || type == Integer.TYPE) {
param = RandomUtils.nextInt();
} else if (type == Long.class || type == Long.TYPE) {
param = RandomUtils.nextLong();
} else if (type == Float.class || type == Float.TYPE) {
param = RandomUtils.nextFloat();
} else if (type == Double.class || type == Double.TYPE) {
param = RandomUtils.nextDouble();
} else if (type == Boolean.class || type == Boolean.TYPE) {
param = RandomUtils.nextBoolean();
} else if (type == BigInteger.class) {
param = new BigInteger(TEST_BIGINTEGER);
} else if (type == List.class) {
param = new ArrayList<>();
} else if (type == XMLGregorianCalendar.class) {
try {
param = DatatypeFactory.newInstance().newXMLGregorianCalendar();
} catch (DatatypeConfigurationException e) {
throw new IllegalArgumentException(e.getMessage(), e);
}
} else {
Constructor[] constructors = type.getConstructors();
param = constructors[0].newInstance();
}
return param;
}
示例6: testFloatConversion
import org.apache.commons.lang.math.RandomUtils; //導入方法依賴的package包/類
@Test
public void testFloatConversion() throws Exception {
OffsetGrowableFloatWriter writer = new OffsetGrowableFloatWriter(OffsetGrowableFloatWriter.DEFAULT_PRECISION, 2, 4096, PackedInts.DEFAULT);
for (int i = 0; i < 4096; i++) {
float value = RandomUtils.nextFloat() * RandomUtils.nextFloat();
writer.setFloat(i, value);
assertEquals(value, writer.getFloat(i), OffsetGrowableFloatWriter.DEFAULT_PRECISION);
}
}
示例7: testSize
import org.apache.commons.lang.math.RandomUtils; //導入方法依賴的package包/類
@Test
public void testSize() throws Exception {
OffsetGrowableFloatWriter writer = new OffsetGrowableFloatWriter(OffsetGrowableFloatWriter.DEFAULT_PRECISION, 2, 4096, PackedInts.DEFAULT);
for (int i = 0; i < 4096; i++) {
float value = RandomUtils.nextFloat() * RandomUtils.nextFloat();
writer.setFloat(i, value);
assertEquals(value, writer.getFloat(i), OffsetGrowableFloatWriter.DEFAULT_PRECISION);
}
}
示例8: getPosition
import org.apache.commons.lang.math.RandomUtils; //導入方法依賴的package包/類
private String getPosition() {
float random = RandomUtils.nextFloat() * 10;
if (random < 7) {
return positions[0];
} else if (random > 7 && random < 8) {
return positions[1];
} else if (random > 8 && random < 8.5) {
return positions[2];
} else if (random > 8.5 && random < 9.5) {
return positions[3];
} else {
return positions[4];
}
}
示例9: random
import org.apache.commons.lang.math.RandomUtils; //導入方法依賴的package包/類
@Override
public Float random() {
return RandomUtils.nextFloat();
}
示例10: randomFloat0to1
import org.apache.commons.lang.math.RandomUtils; //導入方法依賴的package包/類
public static float randomFloat0to1() {
return RandomUtils.nextFloat();
}
示例11: randomFloat
import org.apache.commons.lang.math.RandomUtils; //導入方法依賴的package包/類
public static float randomFloat(int min, int max) {
return RandomUtils.nextFloat() + RandomUtils.nextInt(max - min);
}