List of usage examples for java.util Random nextBoolean
public boolean nextBoolean()
From source file:org.hellojavaer.testcase.generator.TestCaseGenerator.java
private static void convertNum(long num, Character[] baseChar, Random random, StringBuilder result) { if (num <= 0 && result.length() == 0) { result.insert(0, baseChar[0]);/*w w w. j a v a2 s .co m*/ } else if (num > 0) { int i = (int) (num % baseChar.length); Character ch = random.nextBoolean() ? baseChar[i] : Character.toLowerCase(baseChar[i]); result.insert(0, ch); convertNum(num / baseChar.length, baseChar, random, result); } }
From source file:org.brekka.stillingar.example.FieldTypesDOMTest.java
private static Testing writeConfig() { Random r = new Random(); ConfigurationDocument doc = ConfigurationDocument.Factory.newInstance(); Configuration newConfiguration = doc.addNewConfiguration(); FeatureFlagType featureFlag = newConfiguration.addNewFeatureFlag(); featureFlag.setKey("turbo"); featureFlag.setBooleanValue(true);//from w w w.ja v a2 s . c o m Testing testing = newConfiguration.addNewTesting(); testing.setAnyURI("http://brekka.org/" + RandomStringUtils.randomAlphanumeric(10)); testing.setBoolean(r.nextBoolean()); testing.setByte((byte) r.nextInt()); Calendar cal = Calendar.getInstance(); testing.setDate(cal); testing.setDateTime(cal); testing.setDecimal(BigDecimal.valueOf(r.nextDouble())); testing.setDouble(r.nextDouble()); testing.setFloat(r.nextFloat()); testing.setInt(r.nextInt()); testing.setInteger(BigInteger.valueOf(r.nextLong())); testing.setLanguage("en"); testing.setLong(r.nextLong()); testing.setShort((short) r.nextInt()); testing.setString(RandomStringUtils.randomAlphanumeric(24)); testing.setTime(cal); testing.setUUID(UUID.randomUUID().toString()); testing.setPeriod(new GDuration("P5Y2M10DT15H")); byte[] binary = new byte[32]; r.nextBytes(binary); testing.setBinary(binary); TestSupport.write(doc); return testing; }
From source file:org.apache.hadoop.hive.ql.exec.vector.RandomRowObjectSource.java
public static HiveDecimal getRandHiveDecimal(Random r, DecimalTypeInfo decimalTypeInfo) { while (true) { StringBuilder sb = new StringBuilder(); int precision = 1 + r.nextInt(18); int scale = 0 + r.nextInt(precision + 1); int integerDigits = precision - scale; if (r.nextBoolean()) { sb.append("-"); }//from w ww . j a v a2 s . c om if (integerDigits == 0) { sb.append("0"); } else { sb.append(getRandString(r, DECIMAL_CHARS, integerDigits)); } if (scale != 0) { sb.append("."); sb.append(getRandString(r, DECIMAL_CHARS, scale)); } HiveDecimal bd = HiveDecimal.create(sb.toString()); if (bd.scale() > bd.precision()) { // Sometimes weird decimals are produced? continue; } return bd; } }
From source file:org.apache.solr.response.transform.TestSubQueryTransformer.java
static String[] daveMultiValueSearchParams(Random random, int peopleMult, int deptMult) { return new String[] { "q", "name_s:dave", "indent", "true", "fl", (random().nextBoolean() ? "name_s_dv" : "*") + //"dept_ss_dv, ",subq1:[subquery " + ((random.nextBoolean() ? "" : "separator=,")) + "]", "rows", "" + peopleMult, "subq1.q", "{!terms f=dept_id_s v=$row.dept_ss_dv " + ((random.nextBoolean() ? "" : "separator=,")) + "}", "subq1.fl", "text_t", "subq1.indent", "true", "subq1.rows", "" + (deptMult * 2), "subq1.logParamsList", "q,fl,rows,row.dept_ss_dv" }; }
From source file:juicebox.tools.utils.common.MatrixTools.java
/** * Generate a matrix with randomly initialized 1s and 0s * * @param rows//from w w w . j a v a2 s. c o m * @param cols * @return randomized binary matrix */ private static RealMatrix randomUnitMatrix(int rows, int cols) { Random generator = new Random(); RealMatrix matrix = cleanArray2DMatrix(rows, cols); for (int r = 0; r < rows; r++) for (int c = 0; c < cols; c++) if (generator.nextBoolean()) matrix.setEntry(r, c, 1); return matrix; }
From source file:org.apache.hadoop.hive.serde2.binarysortable.MyTestPrimitiveClass.java
public static HiveDecimal getRandHiveDecimal(Random r, ExtraTypeInfo extraTypeInfo) { while (true) { StringBuilder sb = new StringBuilder(); int precision = 1 + r.nextInt(18); int scale = 0 + r.nextInt(precision + 1); int integerDigits = precision - scale; if (r.nextBoolean()) { sb.append("-"); }//from w w w. ja v a 2s.co m if (integerDigits == 0) { sb.append("0"); } else { sb.append(getRandString(r, DECIMAL_CHARS, integerDigits)); } if (scale != 0) { sb.append("."); sb.append(getRandString(r, DECIMAL_CHARS, scale)); } HiveDecimal dec = HiveDecimal.create(sb.toString()); extraTypeInfo.precision = dec.precision(); extraTypeInfo.scale = dec.scale(); return dec; } }
From source file:org.apache.hadoop.hive.ql.exec.vector.VectorRandomRowSource.java
public static HiveDecimal getRandHiveDecimal(Random r, DecimalTypeInfo decimalTypeInfo) { while (true) { StringBuilder sb = new StringBuilder(); int precision = 1 + r.nextInt(18); int scale = 0 + r.nextInt(precision + 1); int integerDigits = precision - scale; if (r.nextBoolean()) { sb.append("-"); }// w ww . j av a 2 s . c o m if (integerDigits == 0) { sb.append("0"); } else { sb.append(RandomTypeUtil.getRandString(r, DECIMAL_CHARS, integerDigits)); } if (scale != 0) { sb.append("."); sb.append(RandomTypeUtil.getRandString(r, DECIMAL_CHARS, scale)); } HiveDecimal bd = HiveDecimal.create(sb.toString()); if (bd.scale() > bd.precision()) { // Sometimes weird decimals are produced? continue; } return bd; } }
From source file:org.latticesoft.util.common.NumeralUtil.java
/** * Generates next random boolean/*w w w . j ava2 s .c o m*/ * @return the generated boolean */ public static boolean getRandomBoolean() { Random rand = new Random(System.currentTimeMillis()); return rand.nextBoolean(); }
From source file:org.apache.hadoop.fs.TestAppendStress.java
private static void writeToFile(Random random, FSDataOutputStream out, int len, DataChecksum checksum) throws IOException { if (len == 0) { return;//w w w . ja v a2 s. co m } LOG.info("Write " + len + " bytes to file."); int bufferSize = 1024 * 1024; byte[] buffer = new byte[bufferSize]; int toLen = len; while (toLen > 0) { random.nextBytes(buffer); int numWrite = Math.min(toLen, buffer.length); out.write(buffer, 0, numWrite); checksum.update(buffer, 0, numWrite); toLen -= numWrite; // randomly do sync or not. if (random.nextBoolean()) { out.sync(); } } }
From source file:truco.plugin.utils.Utils.java
public static void spawnRandomFirework(Location loc) { Firework fw = (Firework) loc.getWorld().spawnEntity(loc, EntityType.FIREWORK); FireworkMeta fwm = fw.getFireworkMeta(); Random r = CardWarsPlugin.random; int rt = r.nextInt(4) + 1; FireworkEffect.Type type = FireworkEffect.Type.BALL; if (rt == 1) { type = FireworkEffect.Type.BALL; }//from w ww .j av a 2 s . c om if (rt == 2) { type = FireworkEffect.Type.BALL_LARGE; } if (rt == 3) { type = FireworkEffect.Type.BURST; } if (rt == 4) { type = FireworkEffect.Type.CREEPER; } if (rt == 5) { type = FireworkEffect.Type.STAR; } Color c1 = Color.fromRGB(170, 0, 0); Color c2 = Color.WHITE; Color c3 = Color.GRAY; FireworkEffect effect = FireworkEffect.builder().flicker(r.nextBoolean()).withColor(c1).withColor(c2) .withFade(c3).with(type).trail(r.nextBoolean()).build(); fwm.addEffect(effect); int rp = r.nextInt(2) + 1; fwm.setPower(rp); fw.setFireworkMeta(fwm); }