List of usage examples for java.lang Math random
public static double random()
From source file:Main.java
/** * Given a byte array of content, writes it to a temporary file and then * returns the path to it as a URL//from ww w . j av a 2 s .c o m * @param contents The content of the file * @param type The file extension to use * @throws IOException if an error occurs */ public static URL stringToTempFile(byte[] contents, String type) throws IOException { // Make sure we have a temp directory checkForTempDirectory(); // Generate a random file name and keep doing it until we get a unique one File f = null; String fName = null; do { fName = tempDirectory + File.separator + ((int) (Math.random() * 10000000)) + "." + type; f = new File(fName); } while (f.exists()); System.out.println("TEMP: Creating temp file " + fName); FileOutputStream out = new FileOutputStream(f); out.write(contents); out.close(); // Remember this file for later deletion tempFileList.add(fName); return new URL("file://" + fName); }
From source file:com.lzhao.framework.spring_hibernate.demo.util.RandomUtil.java
public static String randomStateAbbr() { return STATES_ABBR[(int) (Math.random() * (STATES_ABBR.length - 1))]; }
From source file:Main.java
public static int irandom(int b) // Random integer within range {0,...,b} { return (int) ((b + 1) * Math.random()); }
From source file:Main.java
public static double normal(double u, double s) // Random normal distribution with mean u and standard deviation s { double fac, rsq, v1, v2; if (iset == 0) { do {/* w w w. j a va2 s .c o m*/ v1 = 2.0 * Math.random() - 1.0; v2 = 2.0 * Math.random() - 1.0; rsq = v1 * v1 + v2 * v2; } while (rsq >= 1.0 || rsq == 0.0); fac = Math.sqrt(-2.0 * Math.log(rsq) / rsq); gset = v1 * fac; iset = 1; return (u + s * (v2 * fac)); } else { iset = 0; return (u + s * gset); } }
From source file:org.jfree.chart.demo.DifferenceChartDemo1.java
private static XYDataset createDataset() { TimeSeries timeseries = new TimeSeries("Random 1"); TimeSeries timeseries1 = new TimeSeries("Random 2"); double d = 0.0D; double d1 = 0.0D; Day day = new Day(); for (int i = 0; i < 200; i++) { d = (d + Math.random()) - 0.5D; d1 = (d1 + Math.random()) - 0.5D; timeseries.add(day, d);//from w w w. j a va2 s. c o m timeseries1.add(day, d1); day = (Day) day.next(); } TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(); timeseriescollection.addSeries(timeseries); timeseriescollection.addSeries(timeseries1); return timeseriescollection; }
From source file:org.jfree.chart.demo.DeviationRendererDemo1.java
private static XYDataset createDataset() { YIntervalSeries series1 = new YIntervalSeries("Series 1"); YIntervalSeries series2 = new YIntervalSeries("Series 2"); double d = 100D; double d1 = 100D; for (int i = 0; i <= 100; i++) { d = (d + Math.random()) - 0.47999999999999998D; double d2 = 0.050000000000000003D * (double) i; series1.add(i, d, d - d2, d + d2); d1 = (d1 + Math.random()) - 0.5D; double d3 = 0.070000000000000007D * (double) i; series2.add(i, d1, d1 - d3, d1 + d3); }// w ww. ja va2 s . com YIntervalSeriesCollection dataset = new YIntervalSeriesCollection(); dataset.addSeries(series1); dataset.addSeries(series2); return dataset; }
From source file:lanchester.TestEigen.java
public static Array2DRowRealMatrix getMat(int num) { Array2DRowRealMatrix mat = new Array2DRowRealMatrix(num, num); for (int i1 = 0; i1 < num; i1++) { for (int i2 = 0; i2 < num; i2++) { mat.setEntry(i1, i2, Math.random()); }/*from w w w .ja v a2s.com*/ } return mat; }
From source file:gov.jgi.meta.hadoop.input.FastqBlockLineReader.java
public static void main(String[] args) { int num = 100; int last = -1; do {/*from ww w. j a v a 2 s .co m*/ try { FileInputStream fstream = new FileInputStream("/ifs/scratch/karan/derep-perf/HiSeq-8343080.fq"); FastqBlockLineReader fblr = new FastqBlockLineReader(fstream); Text key = new Text(); Map<String, String> setofreads = new HashMap<String, String>(); int length = (int) (Math.random() * 1000000); System.out.println("iteration " + num + " length = " + length); int total = 0; fblr.readLine(key, setofreads, Integer.MAX_VALUE, length); // System.out.println("setofreads.size = " + setofreads.size()); total += setofreads.size(); //for (String s : setofreads.keySet()) { // System.out.println(s); // } int m = 0; while (setofreads.size() > 0) { System.out.print("."); if ((++m) % 80 == 0) System.out.print("\n"); setofreads.clear(); fblr.readLine(key, setofreads, Integer.MAX_VALUE, length); // System.out.println("setofreads.size = " + setofreads.size()); total += setofreads.size(); } System.out.println("\ntotal = " + total); if (last != -1) { if (last != total) { System.out.println( "error!!!, length = " + length + ": last = " + last + " current = " + total); } } last = total; } catch (Exception e) { System.out.println(e); } } while (num-- > 0); }
From source file:jquery.service.NombreAleatoireService.java
public int nombreAleatoire(int borneInf, int borneSup) { int i = (int) (Math.random() * 1000) % (borneSup + 1 - borneInf) + borneInf; return i;// w w w . j a v a2s . com }
From source file:ar.gob.ambiente.servicios.gestionpersonas.entidades.util.CriptPass.java
/** * Mtodo para crear las contraseas de manera aleatoria al crear un usuario por primera vez * @return //from ww w . j a va2 s . co m */ public static String generar() { int longitud = base.length(); String contrasenia = ""; for (int i = 0; i < 8; i++) { int numero = (int) (Math.random() * (longitud)); String caracter = base.substring(numero, numero + 1); contrasenia = contrasenia + caracter; } return contrasenia; }