Example usage for java.lang Math random

List of usage examples for java.lang Math random

Introduction

In this page you can find the example usage for java.lang Math random.

Prototype

public static double random() 

Source Link

Document

Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0 .

Usage

From source file:playground.wrashid.tryouts.mess.Boxplot.java

private static BoxAndWhiskerCategoryDataset createSampleDataset() {

    final int seriesCount = 3;
    final int categoryCount = 4;
    final int entityCount = 22;

    final DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();
    for (int i = 0; i < seriesCount; i++) {
        for (int j = 0; j < categoryCount; j++) {
            final List list = new ArrayList();
            // add some values...
            for (int k = 0; k < entityCount; k++) {
                final double value1 = 10.0 + Math.random() * 3;
                list.add(new Double(value1));
                final double value2 = 11.25 + Math.random(); // concentrate values in the middle
                list.add(new Double(value2));
            }/*www  .j  a  va  2 s .  c om*/
            dataset.add(list, "Series " + i, " Type " + j);
        }

    }

    return dataset;
}

From source file:org.hsweb.web.oauth2.service.OAuth2ClientServiceImpl.java

@Override
public String refreshSecret(String clientId) {
    String secret = MD5.encode(UUID.randomUUID().toString() + Math.random());
    int size = oAuth2ClientMapper
            .update((UpdateParam) UpdateMapParam.build().set("secret", secret).where("id", clientId));
    if (size != 1)
        throw new NotFoundException("?");
    return secret;
}

From source file:com.pinterest.terrapin.storage.HFileReaderTest.java

@BeforeClass
public static void setUp() throws Exception {
    int randomNum = (int) (Math.random() * Integer.MAX_VALUE);
    hfilePath = "/tmp/hfile-" + randomNum;
    Configuration conf = new Configuration();
    FileSystem fs = FileSystem.get(conf);
    keyValueMap = Maps.newHashMapWithExpectedSize(10000);
    errorKeys = Sets.newHashSetWithExpectedSize(2000);
    StoreFile.Writer writer = new StoreFile.WriterBuilder(conf, new CacheConfig(conf), fs, 4096)
            .withFilePath(new Path(hfilePath)).withCompression(Compression.Algorithm.NONE).build();
    // Add upto 10K values.
    for (int i = 0; i < 10000; i++) {
        byte[] key = String.format("%04d", i).getBytes();
        byte[] value = null;
        // Add a couple of empty values for testing and making sure we return them.
        if (i <= 1) {
            value = "".getBytes();
        } else {/*from www .ja  v a  2  s.  c o  m*/
            value = ("v" + (i + 1)).getBytes();
        }
        KeyValue kv = new KeyValue(key, Bytes.toBytes("cf"), Bytes.toBytes(""), value);
        writer.append(kv);
        keyValueMap.put(ByteBuffer.wrap(key), ByteBuffer.wrap(value));
        if (i >= 4000 && i < 6000) {
            errorKeys.add(ByteBuffer.wrap(key));
        }
    }
    writer.close();
    hfileReader = new TestHFileReader(fs, hfilePath, new CacheConfig(conf),
            new ExecutorServiceFuturePool(Executors.newFixedThreadPool(1)), errorKeys);
}

From source file:io.ecarf.core.cloud.task.common.DoUploadOutputLogTask.java

@Override
public void run() throws IOException {

    log.info("Uploading logs file");

    CloudService cloudService = this.getCloudService();

    if (StringUtils.isBlank(logFile)) {
        logFile = Config.getProperty(Constants.OUTPUT_FILE_KEY);
    }/*from  w  w w.j a va  2 s. c om*/

    if (StringUtils.isBlank(logFolder)) {
        logFolder = Config.getProperty(Constants.OUTPUT_FOLDER_KEY);
    }

    String instanceId = cloudService.getInstanceId();

    // get a random number just in case two instances have the same id, which is true for the coordinator
    //int random = (int) (Math.random() * 1001);
    if (StringUtils.isBlank(jobId)) {
        jobId = "_" + Integer.toString((int) (Math.random() * 1001));
    } else {
        jobId = "_" + jobId;
    }

    String newLogFile = logFolder + Constants.OUTPUT + instanceId + jobId + Constants.DOT_LOG;
    log.info("Copying output log to " + newLogFile);
    FileUtils.copyFile(logFolder + logFile, newLogFile);

    // upload the file to cloud storage
    cloudService.uploadFileToCloudStorage(newLogFile, bucket);

    log.info("Successfully uploaded logs file");
}

From source file:com.indicator_engine.graphgenerator.cewolf.PageViewCountData.java

/**
 *  Produces some random data.//from   w w w  . j  a  va2s  . co  m
 */
public Object produceDataset(Map params) throws DatasetProduceException {
    log.debug("producing data.");
    DefaultCategoryDataset dataset = new DefaultCategoryDataset() {
        /**
         * @see java.lang.Object#finalize()
         */
        protected void finalize() throws Throwable {
            super.finalize();
            log.debug(this + " finalized.");
        }
    };
    for (int series = 0; series < seriesNames.length; series++) {
        int lastY = (int) (Math.random() * 1000 + 1000);
        for (int i = 0; i < categories.length; i++) {
            final int y = lastY + (int) (Math.random() * 200 - 100);
            lastY = y;
            dataset.addValue(y, seriesNames[series], categories[i]);
        }
    }
    return dataset;
}

From source file:net.solarnetwork.node.job.RandomizedCronTriggerBean.java

@Override
public void setCronExpression(String cronExpression) throws ParseException {
    this.baseCronExpression = cronExpression;
    if (randomSecond) {
        int seconds = (int) Math.floor(Math.random() * 60);
        String newExpression = cronExpression.replaceAll("^\\s*\\d+(\\s+)", String.valueOf(seconds) + "$1");
        if (!newExpression.equals(cronExpression)) {
            log.debug("Randomized seconds of cron expression set to {}", seconds);
            cronExpression = newExpression;
        }//from   w w  w  .ja v a  2 s  .  c  om
    }
    super.setCronExpression(cronExpression);
}

From source file:com.atlassian.jira.web.action.setup.SetupProductBundleHelper.java

public void enableWebSudo() {
    final HttpClient httpClient = prepareClient();
    final PostMethod method = new PostMethod(getWebSudoUrl());

    final String token = DigestUtils
            .shaHex(String.valueOf(System.currentTimeMillis() + String.valueOf(Math.random())));
    sharedVariables.setWebSudoToken(token);

    try {//from  w  w w .  j a va  2  s .  com
        method.setParameter("webSudoToken", token);

        final int status = httpClient.executeMethod(method);
        if (status == 200) {
            saveCookies(httpClient.getState().getCookies());
        } else {
            log.warn("Problem when enabling websudo during product bundle license installation, status code: "
                    + status);
        }
    } catch (final IOException e) {
        log.warn("Problem when enabling websudo during product bundle license installation", e);
    } finally {
        method.releaseConnection();
    }
}

From source file:org.openbaton.vnfm.dummy.DummyAMQPVNFManager.java

/**
 * This operation allows creating a VNF instance.
 *
 * @param virtualNetworkFunctionRecord/*  w w w .j a va2  s  . c o  m*/
 * @param scripts
 */
@Override
public VirtualNetworkFunctionRecord instantiate(VirtualNetworkFunctionRecord virtualNetworkFunctionRecord,
        Object scripts, Map<String, Collection<VimInstance>> vimInstances) throws Exception {
    log.info("Instantiation of VirtualNetworkFunctionRecord " + virtualNetworkFunctionRecord.getName());

    // vnfmHelper.saveScriptOnEms(virtualNetworkFunctionRecord, scripts);

    log.debug("added parameter to config");
    log.debug("CONFIGURATION: " + virtualNetworkFunctionRecord.getConfigurations());
    ConfigurationParameter cp = new ConfigurationParameter();
    cp.setConfKey("new_key");
    cp.setValue("new_value");
    virtualNetworkFunctionRecord.getConfigurations().getConfigurationParameters().add(cp);

    Thread.sleep((int) (Math.random() * 5000) + 4000);

    return virtualNetworkFunctionRecord;
}

From source file:layout.BoxLayoutDemo2.java

public void populateContentPane(Container contentPane) {
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));

    //Create the rectangles.
    int shortSideSize = 15;
    for (int i = 0; i < NUM_COMPONENTS; i++) {
        if (sizeIsRandom) {
            shortSideSize = (int) (30.0 * Math.random()) + 30;
        } else {//w  w w . j  a va2 s  .c  o  m
            shortSideSize += 10;
        }
        bldComponent[i] = new BLDComponent(xAlignment[i], hue[i], shortSideSize, restrictSize, sizeIsRandom,
                String.valueOf(i));
        panel.add(bldComponent[i]);
    }

    //Create the instructions.
    JLabel label = new JLabel("Click a rectangle to " + "change its X alignment.");
    JCheckBox cb = new JCheckBox("Restrict maximum rectangle size.");
    cb.setSelected(restrictSize);
    cb.addItemListener(this);

    panel.setBorder(BorderFactory.createLineBorder(Color.red));

    Box box = Box.createVerticalBox();
    box.add(label);
    box.add(cb);

    contentPane.add(panel, BorderLayout.CENTER);
    contentPane.add(box, BorderLayout.PAGE_END);
}

From source file:org.jfree.chart.demo.MultipleAxisDemo4.java

private static XYDataset createDataset(String s, double d, RegularTimePeriod regulartimeperiod, int i) {
    TimeSeries timeseries = new TimeSeries(s);
    RegularTimePeriod regulartimeperiod1 = regulartimeperiod;
    double d1 = d;
    for (int j = 0; j < i; j++) {
        timeseries.add(regulartimeperiod1, d1);
        regulartimeperiod1 = regulartimeperiod1.next();
        d1 *= 1.0D + (Math.random() - 0.495D) / 10D;
    }/* w  w w  .ja v a  2s.c o m*/

    TimeSeriesCollection timeseriescollection = new TimeSeriesCollection();
    timeseriescollection.addSeries(timeseries);
    return timeseriescollection;
}