List of usage examples for java.util Random Random
public Random(long seed)
From source file:Main.java
public static void genRandom(long seed, int max, int factor, int offset, int array[]) { Random r = new Random(seed); for (int i = 0; i < array.length; i++) { array[i] = (r.nextInt(max) * factor + offset); }//from www . j a v a2 s . co m }
From source file:Main.java
public static <T extends BroadcastReceiver> void scheduleUpdate(Context context, Class<T> clazz) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, clazz); PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); Random random = new Random(System.currentTimeMillis()); long offset = random.nextLong() % (12 * 60 * 60 * 1000); long interval = (24 * 60 * 60 * 1000) + offset; String prefKey = "pref_scheduled_monitor_config_update_" + clazz.getCanonicalName(); long scheduledTime = preferences.getLong(prefKey, -1); if (scheduledTime == -1) { context.sendBroadcast(intent);/* w ww . j a va 2s . c o m*/ } if (scheduledTime <= System.currentTimeMillis()) { context.sendBroadcast(intent); scheduledTime = System.currentTimeMillis() + interval; preferences.edit().putLong(prefKey, scheduledTime).commit(); Log.w("PeriodicActionUtils", "Scheduling for all new time: " + scheduledTime + " (" + clazz.getSimpleName() + ")"); } else { Log.w("PeriodicActionUtils", "Scheduling for time found in preferences: " + scheduledTime + " (" + clazz.getSimpleName() + ")"); } am.cancel(sender); am.set(AlarmManager.RTC_WAKEUP, scheduledTime, sender); Log.w("PeriodicActionUtils", "Scheduled for: " + scheduledTime + " (" + clazz.getSimpleName() + ")"); }
From source file:com.jivesoftware.os.jive.utils.id.IdTest.java
@Test public void idStringTest() throws Exception { final Random r = new Random(1234); for (int i = 0; i < 100; i++) { long id = Math.abs(r.nextLong()); Id wid = new Id(id); Id rid = MAPPER.readValue(MAPPER.writeValueAsString(wid), Id.class); Assert.assertEquals(rid, wid, "Failed to map Id through String: " + id); }/*from www .j av a 2 s . co m*/ }
From source file:iddb.core.util.PasswordUtils.java
public static String hashPassword(String raw_password) { Random random = new Random(raw_password.length() + System.currentTimeMillis()); String salt = StringUtils.left(HashUtils.getSHA1Hash( Float.toHexString(random.nextFloat()) + Float.toHexString(System.currentTimeMillis())), 5); String hashedPassword = HashUtils.getSHA1Hash(salt + raw_password); return salt + "$" + hashedPassword; }
From source file:info.rmarcus.birkhoffvonneumann.ChiSquaredTest.java
public static void testMethod(SamplingAlgorithm samp, int n, int samples) throws BVNException { double[][] bistoc = MatrixUtils.uniformBistoc(n); long[] classes = new long[factorial(bistoc.length)]; BVNDecomposer bvn = new BVNDecomposer(); bvn.setSamplingAlgorithm(samp);/*w w w . j a va 2s .co m*/ Random r = new Random(42); for (int i = 0; i < samples; i++) { int[] p = CoeffAndMatrix.asFlatPerm(bvn.sample(r, bistoc)); classes[inv(p)]++; } double[] expected = new double[classes.length]; for (int i = 0; i < expected.length; i++) expected[i] = (double) classes.length / (double) samples; ChiSquareTest chiT = new ChiSquareTest(); double testStat = chiT.chiSquare(expected, classes); ChiSquaredDistribution chi = new ChiSquaredDistribution(classes.length - 1); System.out.println(Arrays.toString(classes)); System.out.println(chi.cumulativeProbability(testStat) + "\t" + testStat); }
From source file:com.dianping.dpsf.other.echo.SimpleEchoClient.java
private static List<String[]> generateHostList() { List<String[]> hostList = new ArrayList<String[]>(); hostList.add(new String[] { "127.0.0.1", "20001" }); hostList.add(new String[] { "127.0.0.1", "20002" }); hostList.add(new String[] { "127.0.0.1", "20003" }); Random rnd = new Random(System.currentTimeMillis()); int num = rnd.nextInt(3) + 1; Collections.shuffle(hostList); return hostList.subList(0, num); }
From source file:com.linkedin.paldb.impl.GenerateTestData.java
public static Integer[] generateRandomIntKeys(int count, int range, long seed) { Random random = new Random(seed); Set<Integer> set = new HashSet<Integer>(count); while (set.size() < count) { set.add(random.nextInt(range));// w ww .j av a2 s . c o m } return set.toArray(new Integer[0]); }
From source file:com.rtg.alignment.SingleIndelEditDistanceTest.java
private static String randomDNA(final long seed, final int length) { final Random rand = new Random(seed); final StringBuilder sb = new StringBuilder(); for (int i = 0; i < length; i++) { final int dna = rand.nextInt(4); final String dnac = DNA_STRINGS[dna]; sb.append(dnac);//w w w .j ava2s . co m } return sb.toString(); }
From source file:enumj.EnumerableGenerator.java
public static Enumerable<EnumerableGenerator> generators() { final Random rnd = new Random(9691); return Enumerable.of(() -> Optional.of(new EnumerableGenerator(rnd.nextLong()))); }
From source file:Main.java
public static void genRandom(long seed, int factor, int offset, int array[], int stride, int skip) { Random r = new Random(seed); for (int i = 0; i < array.length / stride; i++) { for (int j = 0; j < stride; j++) { if (j >= stride - skip) array[i * stride + j] = 0; else/*from ww w . ja v a 2 s. com*/ array[i * stride + j] = r.nextInt() * factor + offset; } } }