List of usage examples for java.util Random Random
public Random()
From source file:com.sawyer.advadapters.app.adapters.jsonadapter.UnitTestJSONArrayActivity.java
private static boolean getBoolean() { return new Random().nextBoolean(); }
From source file:com.linkedin.pinot.core.data.readers.PinotSegmentUtil.java
public static List<GenericRow> createTestData(Schema schema, int numRows) { List<GenericRow> rows = new ArrayList<>(); final Random random = new Random(); Map<String, Object> fields; for (int i = 0; i < numRows; i++) { fields = new HashMap<>(); for (FieldSpec fieldSpec : schema.getAllFieldSpecs()) { Object value;//from w w w. ja v a 2 s. c o m if (fieldSpec.isSingleValueField()) { value = generateSingleValue(random, fieldSpec.getDataType()); } else { value = generateMultiValue(random, fieldSpec.getDataType()); } fields.put(fieldSpec.getName(), value); } GenericRow row = new GenericRow(); row.init(fields); rows.add(row); } return rows; }
From source file:com.controller.RandomController.java
@RequestMapping(value = "getRandom.htm", method = RequestMethod.GET) public @ResponseBody String getRandom() { Random rnd = new Random(); String result = "<br/>Response from controller " + rnd.nextFloat() * 100 + " time " + new Date().toString(); return result; }
From source file:UUIDGenerator.java
protected static synchronized void getInitialUUID() { if (baseUUID != null) { return;/* www .j a v a2 s . c o m*/ } if (myRand == null) { myRand = new Random(); } long rand = myRand.nextLong(); String sid; try { sid = InetAddress.getLocalHost().toString(); } catch (UnknownHostException e) { sid = Thread.currentThread().getName(); } StringBuffer sb = new StringBuffer(); sb.append(sid); sb.append(":"); sb.append(Long.toString(rand)); MessageDigest md5 = null; try { md5 = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { //todo have to be properly handled } md5.update(sb.toString().getBytes()); byte[] array = md5.digest(); StringBuffer sb2 = new StringBuffer(); for (int j = 0; j < array.length; ++j) { int b = array[j] & 0xFF; sb2.append(Integer.toHexString(b)); } int begin = myRand.nextInt(); if (begin < 0) begin = begin * -1; begin = begin % 8; baseUUID = sb2.toString().substring(begin, begin + 18).toUpperCase(); }
From source file:com.attilax.zip.FileUtil.java
/** * ????/*from w ww . j a v a 2 s. co m*/ * @param seed ??? * @return */ public static String getRandomFileName(String seed) { byte[] ra = new byte[100]; new Random().nextBytes(ra); StringBuilder build = new StringBuilder(""); for (int i = 0; i < ra.length; i++) { build.append(Byte.valueOf(ra[i]).toString()); } String currentDate = Long.valueOf(new Date().getTime()).toString(); seed = seed + currentDate + build.toString(); // return EncryptUtils.getMD5ofStr(seed).toLowerCase(); return ""; }
From source file:com.mmj.app.common.util.SerialNumGenerator.java
/** ? */ public static String RandomString(int length) { String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; Random random = new Random(); StringBuffer buf = new StringBuffer(); for (int i = 0; i < length; i++) { int num = random.nextInt(62); buf.append(str.charAt(num));/*w w w . ja v a 2 s .c o m*/ } return buf.toString(); }
From source file:io.druid.query.aggregation.datasketches.tuple.GenerateTestData.java
private static void generateSketches() throws Exception { Path path = FileSystems.getDefault().getPath("array_of_doubles_sketch_data.tsv"); try (BufferedWriter out = Files.newBufferedWriter(path, StandardCharsets.UTF_8)) { Random rand = new Random(); int key = 0; for (int i = 0; i < 20; i++) { ArrayOfDoublesUpdatableSketch sketch = new ArrayOfDoublesUpdatableSketchBuilder() .setNominalEntries(1024).build(); sketch.update(key++, new double[] { 1 }); sketch.update(key++, new double[] { 1 }); out.write("2015010101"); out.write('\t'); out.write("product_" + (rand.nextInt(10) + 1)); out.write('\t'); out.write(Base64.encodeBase64String(sketch.compact().toByteArray())); out.newLine();//w ww.jav a2 s. c o m } } }
From source file:e.pkg3.pkg6a.acertijo.acertijo.java
/** * Creates new form acertijo/*from w w w . ja v a 2 s . c o m*/ */ public acertijo() { initComponents(); rnd = new Random(); numero_Aleatorio = rnd.nextInt(100) + 1; System.out.println("" + numero_Aleatorio); inicio = Calendar.getInstance(); }
From source file:com.snowplowanalytics.snowplow.tracker.core.Util.java
public static int getTransactionId() { Random r = new Random(); //NEED ID RANGE return r.nextInt(999999 - 100000 + 1) + 100000; }
From source file:com.awcoleman.ExampleJobSummaryLogWithOutput.utility.CreateBinaryDatafile.java
public CreateBinaryDatafile(int numrecs) throws IOException { Random rangen = new Random(); long recid = 0; try (DataOutputStream out = new DataOutputStream(new FileOutputStream("/tmp/sampleDatafile.bin"));) { for (int ii = 0; ii < numrecs; ii++) { out.writeUTF(RandomStringUtils.randomAlphabetic(10)); out.writeLong(++recid);//from ww w. ja v a 2s .co m out.writeInt(rangen.nextInt(32)); out.writeInt(rangen.nextInt(3600)); out.writeUTF(generateDatetime()); } } }