Example usage for java.util Random nextDouble

List of usage examples for java.util Random nextDouble

Introduction

In this page you can find the example usage for java.util Random nextDouble.

Prototype

public double nextDouble() 

Source Link

Document

Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 from this random number generator's sequence.

Usage

From source file:MainClass.java

public static void main(String args[]) {
    Random rand = new Random();
    System.out.println(rand.nextDouble());
}

From source file:Main.java

public static void main(String args[]) {

    Random randomno = new Random();

    // check next double value  
    System.out.println("Next double value: " + randomno.nextDouble());
}

From source file:Random2.java

public static void main(String[] argv) {
    //+//from  w  ww  .j  a  v a  2s .  co  m
    // java.util.Random methods are non-static, so need to construct
    Random r = new Random();
    for (int i = 0; i < 10; i++)
        System.out.println("A double from java.util.Random is " + r.nextDouble());
    for (int i = 0; i < 10; i++)
        System.out.println("An integer from java.util.Random is " + r.nextInt());
    //-
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    Random rand = new Random();

    boolean b = rand.nextBoolean();
    long l = rand.nextLong();
    float f = rand.nextFloat(); // 0.0 <= f < 1.0
    double d = rand.nextDouble(); // 0.0 <= d < 1.0
}

From source file:Random4.java

public static void main(String[] argv) throws IOException {
    // java.util.Random methods are non-static, do need to construct Math
    Random r = new Random();
    PrintWriter file1 = new PrintWriter(new FileWriter("file1"));
    PrintWriter file2 = new PrintWriter(new FileWriter("file2"));
    for (int i = 0; i < 10000; i++) {
        file1.println(r.nextDouble());
        file2.println(r.nextGaussian());
    }/*from ww  w.ja  va2 s.co  m*/
    file1.close();
    file2.close();
}

From source file:edu.uiowa.icts.util.TopN.java

/**
 * <p>main.</p>/*from   www  .java 2  s. c om*/
 *
 * @param args an array of {@link java.lang.String} objects.
 */
public static void main(String args[]) {
    TopN<Double> top10 = new TopN<Double>(10);
    Random r = new Random();
    for (int i = 0; i < 10000; i++) {
        double d = r.nextDouble();
        int pos = top10.inTopN(d);
        if (pos > 0) {
            log.debug(i + ":  Rank: " + pos + " is in top 10: " + d);
        }
    }

    top10.print();
    log.debug("size: " + top10.size());
    log.debug("max: " + top10.max());

}

From source file:io.druid.query.aggregation.datasketches.quantiles.GenerateTestData.java

public static void main(String[] args) throws Exception {
    Path buildPath = FileSystems.getDefault().getPath("doubles_build_data.tsv");
    Path sketchPath = FileSystems.getDefault().getPath("doubles_sketch_data.tsv");
    BufferedWriter buildData = Files.newBufferedWriter(buildPath, StandardCharsets.UTF_8);
    BufferedWriter sketchData = Files.newBufferedWriter(sketchPath, StandardCharsets.UTF_8);
    Random rand = new Random();
    int sequenceNumber = 0;
    for (int i = 0; i < 20; i++) {
        int product = rand.nextInt(10);
        UpdateDoublesSketch sketch = UpdateDoublesSketch.builder().build();
        for (int j = 0; j < 20; j++) {
            double value = rand.nextDouble();
            buildData.write("2016010101");
            buildData.write('\t');
            buildData.write(Integer.toString(sequenceNumber)); // dimension with unique numbers for ingesting raw data
            buildData.write('\t');
            buildData.write(Integer.toString(product)); // product dimension
            buildData.write('\t');
            buildData.write(Double.toString(value));
            buildData.newLine();/*w ww .  j a v a2  s . co m*/
            sketch.update(value);
            sequenceNumber++;
        }
        sketchData.write("2016010101");
        sketchData.write('\t');
        sketchData.write(Integer.toString(product)); // product dimension
        sketchData.write('\t');
        sketchData.write(Base64.encodeBase64String(sketch.toByteArray(true)));
        sketchData.newLine();
    }
    buildData.close();
    sketchData.close();
}

From source file:org.apache.druid.query.aggregation.datasketches.quantiles.GenerateTestData.java

public static void main(String[] args) throws Exception {
    Path buildPath = FileSystems.getDefault().getPath("doubles_build_data.tsv");
    Path sketchPath = FileSystems.getDefault().getPath("doubles_sketch_data.tsv");
    BufferedWriter buildData = Files.newBufferedWriter(buildPath, StandardCharsets.UTF_8);
    BufferedWriter sketchData = Files.newBufferedWriter(sketchPath, StandardCharsets.UTF_8);
    Random rand = ThreadLocalRandom.current();
    int sequenceNumber = 0;
    for (int i = 0; i < 20; i++) {
        int product = rand.nextInt(10);
        UpdateDoublesSketch sketch = UpdateDoublesSketch.builder().build();
        for (int j = 0; j < 20; j++) {
            double value = rand.nextDouble();
            buildData.write("2016010101");
            buildData.write('\t');
            buildData.write(Integer.toString(sequenceNumber)); // dimension with unique numbers for ingesting raw data
            buildData.write('\t');
            buildData.write(Integer.toString(product)); // product dimension
            buildData.write('\t');
            buildData.write(Double.toString(value));
            buildData.newLine();/*from  w  ww.java  2 s. c om*/
            sketch.update(value);
            sequenceNumber++;
        }
        sketchData.write("2016010101");
        sketchData.write('\t');
        sketchData.write(Integer.toString(product)); // product dimension
        sketchData.write('\t');
        sketchData.write(Base64.encodeBase64String(sketch.toByteArray(true)));
        sketchData.newLine();
    }
    buildData.close();
    sketchData.close();
}

From source file:com.aestel.chemistry.openEye.fp.FPDictionarySorter.java

public static void main(String... args) throws IOException {
    long start = System.currentTimeMillis();
    int iCounter = 0;
    int fpCounter = 0;

    // create command line Options object
    Options options = new Options();
    Option opt = new Option("i", true, "input file [.ism,.sdf,...]");
    opt.setRequired(true);/*from   w ww  . j  a v a  2s .  com*/
    options.addOption(opt);

    opt = new Option("fpType", true, "fingerPrintType: maccs|linear7|linear7*4");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option("sampleFract", true, "fraction of input molecules to use (Default=1)");
    opt.setRequired(false);
    options.addOption(opt);

    CommandLineParser parser = new PosixParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (Exception e) {
        System.err.println(e.getMessage());
        exitWithHelp(options);
    }
    args = cmd.getArgs();

    if (cmd.hasOption("d")) {
        System.err.println("Start debugger and press return:");
        new BufferedReader(new InputStreamReader(System.in)).readLine();
    }

    if (args.length != 0) {
        exitWithHelp(options);
    }

    String type = cmd.getOptionValue("fpType");
    boolean updateDictionaryFile = false;
    boolean hashUnknownFrag = false;
    Fingerprinter fprinter = Fingerprinter.createFingerprinter(type, updateDictionaryFile, hashUnknownFrag);
    OEMolBase mol = new OEGraphMol();

    String inFile = cmd.getOptionValue("i");
    oemolistream ifs = new oemolistream(inFile);

    double fract = 2D;
    String tmp = cmd.getOptionValue("sampleFract");
    if (tmp != null)
        fract = Double.parseDouble(tmp);

    Random rnd = new Random();

    LearningStrcutureCodeMapper mapper = (LearningStrcutureCodeMapper) fprinter.getMapper();
    int dictSize = mapper.getMaxIdx() + 1;
    int[] freq = new int[dictSize];

    while (oechem.OEReadMolecule(ifs, mol)) {
        iCounter++;
        if (rnd.nextDouble() < fract) {
            fpCounter++;

            Fingerprint fp = fprinter.getFingerprint(mol);
            for (int bit : fp.getBits())
                freq[bit]++;
        }

        if (iCounter % 100 == 0)
            System.err.print(".");
        if (iCounter % 4000 == 0) {
            System.err.printf(" %d %d %dsec\n", iCounter, fpCounter,
                    (System.currentTimeMillis() - start) / 1000);
        }
    }

    System.err.printf("FPDictionarySorter: Read %d structures calculated %d fprints in %d sec\n", iCounter,
            fpCounter, (System.currentTimeMillis() - start) / 1000);

    mapper.reSortDictionary(freq);
    mapper.writeDictionary();
    fprinter.close();
}

From source file:jmbench.plots.SummaryWhiskerPlot.java

public static void main(String args[]) {
    Random rand = new Random(2344);

    SummaryWhiskerPlot plot = new SummaryWhiskerPlot("Test Summary", "Weighted by Operation Time");

    for (int i = 0; i < 3; i++) {
        List<Double> overall = new ArrayList<Double>();
        List<Double> large = new ArrayList<Double>();
        List<Double> small = new ArrayList<Double>();

        for (int j = 0; j < 50; j++) {
            overall.add(rand.nextDouble());
            large.add(rand.nextDouble());
            small.add(rand.nextDouble());
        }/*from w  w  w  .  j a v a  2s  . c o  m*/

        plot.addLibrary("Lib " + i, overall, large, small);
    }

    plot.displayWindow(600, 350);
}