List of usage examples for java.util Random Random
public Random(long seed)
From source file:Main.java
public static int getRandom() { Random ran = new Random(System.currentTimeMillis()); int ret = ran.nextInt(); ret = Math.abs(ret);//from w w w . j a v a 2s. c o m return ret; }
From source file:Main.java
@SuppressWarnings("unused") public static String getRandomNumber(int count) { Random rdm = new Random(System.currentTimeMillis()); String random = ""; for (int i = 0; i < count; i++) { String str = String.valueOf((int) (Math.random() * 10 - 1)); random = random + str;/*from ww w.j a va2s . co m*/ } return random; }
From source file:Main.java
public static int generateRandomColour(long seed) { Random random = new Random(seed); int color = Color.argb(random.nextInt(), random.nextInt(), random.nextInt(), random.nextInt()); float[] hsv = new float[3]; Color.colorToHSV(color, hsv); //Adjust the saturation value, less than 1 is darker, greater than 1 is brighter hsv[2] *= 0.8;//from w ww . jav a 2 s.c o m return Color.HSVToColor(hsv); }
From source file:Main.java
/** Returns a random integer between 0 and n-1 */ public static int nextInt(int n) { Random rand = new Random(seed); return Math.abs(rand.nextInt()) % n; }
From source file:Main.java
private static String generateNonce(int length) { Random random = new Random(System.currentTimeMillis()); if (length < 10) length = 10;/*from w w w.j a v a 2 s.c o m*/ int MAX_LEN = NONCE_SAMPLE.length(); StringBuffer buf = new StringBuffer(); for (int i = 0; i < length; i++) { buf.append(NONCE_SAMPLE.charAt(random.nextInt(MAX_LEN))); } return buf.toString(); }
From source file:Main.java
public static String encryptPassword(String s) { int i = 10 + (new Random(SystemClock.currentThreadTimeMillis())).nextInt(90); return (new StringBuilder()).append(md5((new StringBuilder()).append(i).append(s).toString())).append(":") .append(i).toString();//w w w . j a va2s . c o m }
From source file:ffx.numerics.fft.RowMajorComplex3DCuda.java
/** * <p>//from w w w .j a v a 2s. c om * main</p> * * @param args an array of {@link java.lang.String} objects. * @throws java.lang.Exception if any. */ public static void main(String[] args) throws Exception { int dimNotFinal = 64; int reps = 10; if (args != null) { try { dimNotFinal = Integer.parseInt(args[0]); if (dimNotFinal < 1) { dimNotFinal = 64; } reps = Integer.parseInt(args[2]); if (reps < 1) { reps = 5; } } catch (Exception e) { } } final int dim = dimNotFinal; System.out.println(String.format( " Initializing a %d cubed grid.\n" + " The best timing out of %d repititions will be used.", dim, reps)); final int dimCubed = dim * dim * dim; /** * Create an array to save the initial input and result. */ double orig[] = new double[dimCubed]; double answer[] = new double[dimCubed]; double data[] = new double[dimCubed * 2]; double recip[] = new double[dimCubed]; Random random = new Random(1); for (int x = 0; x < dim; x++) { for (int y = 0; y < dim; y++) { for (int z = 0; z < dim; z++) { int index = RowMajorComplex3D.iComplex3D(x, y, z, dim, dim); orig[index / 2] = random.nextDouble(); recip[index / 2] = orig[index / 2]; } } } RowMajorComplex3D complex3D = new RowMajorComplex3D(dim, dim, dim); RowMajorComplex3DParallel complex3DParallel = new RowMajorComplex3DParallel(dim, dim, dim, new ParallelTeam(), IntegerSchedule.fixed()); RowMajorComplex3DCuda complex3DCUDA = new RowMajorComplex3DCuda(dim, dim, dim, data, recip); Thread cudaThread = new Thread(complex3DCUDA); cudaThread.setPriority(Thread.MAX_PRIORITY); cudaThread.start(); double toSeconds = 0.000000001; long parTime = Long.MAX_VALUE; long seqTime = Long.MAX_VALUE; long clTime = Long.MAX_VALUE; complex3D.setRecip(recip); for (int i = 0; i < reps; i++) { for (int j = 0; j < dimCubed; j++) { data[j * 2] = orig[j]; data[j * 2 + 1] = 0.0; } long time = System.nanoTime(); complex3D.convolution(data); time = (System.nanoTime() - time); System.out.println(String.format(" %2d Sequential: %8.3f", i + 1, toSeconds * time)); if (time < seqTime) { seqTime = time; } } for (int j = 0; j < dimCubed; j++) { answer[j] = data[j * 2]; } complex3DParallel.setRecip(recip); for (int i = 0; i < reps; i++) { for (int j = 0; j < dimCubed; j++) { data[j * 2] = orig[j]; data[j * 2 + 1] = 0.0; } long time = System.nanoTime(); complex3DParallel.convolution(data); time = (System.nanoTime() - time); System.out.println(String.format(" %2d Parallel: %8.3f", i + 1, toSeconds * time)); if (time < parTime) { parTime = time; } } double maxError = Double.MIN_VALUE; double rmse = 0.0; for (int i = 0; i < dimCubed; i++) { double error = Math.abs(answer[i] - data[2 * i]); if (error > maxError) { maxError = error; } rmse += error * error; } rmse /= dimCubed; rmse = Math.sqrt(rmse); logger.info(String.format(" Parallel RMSE: %12.10f, Max: %12.10f", rmse, maxError)); for (int i = 0; i < reps; i++) { for (int j = 0; j < dimCubed; j++) { data[j * 2] = orig[j]; data[j * 2 + 1] = 0.0; } long time = System.nanoTime(); complex3DCUDA.convolution(data); time = (System.nanoTime() - time); System.out.println(String.format(" %2d CUDA: %8.3f", i + 1, toSeconds * time)); if (time < clTime) { clTime = time; } } maxError = Double.MIN_VALUE; double avg = 0.0; rmse = 0.0; for (int i = 0; i < dimCubed; i++) { double error = Math.abs((answer[i] - data[2 * i]) / dimCubed); avg += error; if (error > maxError) { maxError = error; } rmse += error * error; } rmse /= dimCubed; avg /= dimCubed; rmse = Math.sqrt(rmse); logger.info(String.format(" CUDA RMSE: %12.10f, Max: %12.10f, Avg: %12.10f", rmse, maxError, avg)); complex3DCUDA.free(); complex3DCUDA = null; System.out.println(String.format(" Best Sequential Time: %8.3f", toSeconds * seqTime)); System.out.println(String.format(" Best Parallel Time: %8.3f", toSeconds * parTime)); System.out.println(String.format(" Best CUDA Time: %8.3f", toSeconds * clTime)); System.out.println(String.format(" Parallel Speedup: %15.5f", (double) seqTime / parTime)); System.out.println(String.format(" CUDA Speedup: %15.5f", (double) seqTime / clTime)); }
From source file:Main.java
/** * @author TheMrMilchmann//from w w w. j ava2 s. c o m * @since DerpieLang v1.0.0 */ public static final <T> T[] fillRandomly(T[] from, T[] into, long seed) { Random random = new Random(seed); for (int i = 0; i < into.length; i++) { into[i] = from[random.nextInt(from.length)]; } return into; }
From source file:Main.java
public static void changeRingtone(Context context) { SharedPreferences preferences = context.getSharedPreferences("randomizer", Context.MODE_PRIVATE); if (!preferences.getBoolean("active", false)) return;/* w ww .j a v a 2 s . c om*/ RingtoneManager mgr = new RingtoneManager(context); Random random = new Random(System.currentTimeMillis()); int n = random.nextInt(mgr.getCursor().getCount()); RingtoneManager.setActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE, mgr.getRingtoneUri(n)); }
From source file:Main.java
public static void changeRingtone(Context context) { SharedPreferences sharedPreferences = context.getSharedPreferences("randomizer", Context.MODE_PRIVATE); if (!sharedPreferences.getBoolean("active", false)) { return;//from w w w.ja v a2 s .c o m } // END if RingtoneManager ringtoneManager = new RingtoneManager(context); Random random = new Random(System.currentTimeMillis()); int count = random.nextInt(ringtoneManager.getCursor().getCount()); RingtoneManager.setActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE, ringtoneManager.getRingtoneUri(count)); }