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:hu.vpmedia.media.red5.bwcheck.BandwidthDetection.java

public void calculateClientBw(IConnection p_client) {

    for (int i = 0; i < 1200; i++) {
        payload[i] = Math.random();
    }//from w w w.ja  v  a 2  s.  com

    p_client.setAttribute("payload", payload);

    for (int i = 0; i < 12000; i++) {
        payload_1[i] = Math.random();
    }

    p_client.setAttribute("payload_1", payload_1);

    for (int i = 0; i < 12000; i++) {
        payload_2[i] = Math.random();
    }

    p_client.setAttribute("payload_2", payload_2);

    final IStreamCapableConnection beginningStats = this.getStats();
    final Long start = new Long(System.nanoTime() / 1000000); //new Long(System.currentTimeMillis());

    this.client = p_client;
    beginningValues = new HashMap<String, Long>();
    beginningValues.put("b_down", beginningStats.getWrittenBytes());
    beginningValues.put("b_up", beginningStats.getReadBytes());
    beginningValues.put("time", start);

    this.pakSent.add(start);
    this.sent++;
    log.info("Starting bandwidth check at " + start);
    this.callBWCheck("");

}

From source file:org.openhie.openempi.service.MailEngineTest.java

public void testSend() throws Exception {
    // mock smtp server
    Wiser wiser = new Wiser();
    // set the port to a random value so there's no conflicts between tests
    int port = 2525 + (int) (Math.random() * 100);
    mailSender.setPort(port);/*from w w  w  .  ja v a 2 s  .c  om*/
    wiser.setPort(port);
    wiser.start();

    Date dte = new Date();
    this.mailMessage.setTo("foo@bar.com");
    String emailSubject = "grepster testSend: " + dte;
    String emailBody = "Body of the grepster testSend message sent at: " + dte;
    this.mailMessage.setSubject(emailSubject);
    this.mailMessage.setText(emailBody);
    this.mailEngine.send(this.mailMessage);

    wiser.stop();
    assertTrue(wiser.getMessages().size() == 1);
    WiserMessage wm = wiser.getMessages().get(0);
    assertEquals(emailSubject, wm.getMimeMessage().getSubject());
    assertEquals(emailBody, wm.getMimeMessage().getContent());
}

From source file:org.trendafilov.odesk.notifier.Main.java

public void startup() {
    ScheduledExecutorService executor = Executors.newScheduledThreadPool(2);
    executor.scheduleAtFixedRate(alertDeamon, 1, 1, TimeUnit.MINUTES);

    while (true) {
        executor.submit(newJobPooler);/*from w w  w.  ja  v  a 2  s  .  c  om*/
        int randomDelay = 3 + (int) (Math.random() * 5);
        Logger.info(String.format("Sleeping for: [%s]", randomDelay));
        try {
            Thread.sleep(randomDelay * 1000 * 60);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}

From source file:discovery.ExampleServer.java

public ExampleServer(CuratorFramework client, String path, String serviceName, String description)
        throws Exception {
    // in a real application, you'd have a convention of some kind for the URI layout
    UriSpec uriSpec = new UriSpec("{scheme}://foo.com:{port}");

    thisInstance = ServiceInstance.<InstanceDetails>builder().name(serviceName)
            .payload(new InstanceDetails(description)).port((int) (65535 * Math.random())) // in a real application, you'd use a common port
            .uriSpec(uriSpec).build();//w  w w  . j  a v  a 2  s . co  m

    // if you mark your payload class with @JsonRootName the provided JsonInstanceSerializer will work
    JsonInstanceSerializer<InstanceDetails> serializer = new JsonInstanceSerializer<InstanceDetails>(
            InstanceDetails.class);

    serviceDiscovery = ServiceDiscoveryBuilder.builder(InstanceDetails.class).client(client).basePath(path)
            .serializer(serializer).thisInstance(thisInstance).build();
}

From source file:com.almende.eve.ggdemo.HolonAgent.java

public void create(@Name("neighbours") ArrayList<String> nbs, @Name("stepSize") Integer stepSize)
        throws JSONRPCException, IOException {

    neighbours = new HashSet<String>(nbs);
    getState().put("neighbours", neighbours);

    if (stepSize > neighbours.size()) {
        stepSize = neighbours.size();//from   w  w w  . j a  v  a2  s  .c o  m
    }
    getState().put("stepSize", stepSize);

    String taskId = getScheduler().createTask(new JSONRequest("checkMerge", null), (int) Math.random() * 1500);
    System.out.println(getId() + ": schedulertask created:" + taskId + " --> " + getScheduler());
}

From source file:org.openmrs.web.taglib.DisplayChartTag.java

/**
 * Render graph./*from w w  w .  j  av a 2  s  .  c om*/
 *
 * @return return result code
 */
public int doStartTag() throws JspException {
    if (chart != null) {
        try {
            HttpSession session = pageContext.getSession();
            HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();

            Long time = System.currentTimeMillis();
            Double random = Math.random() * 1000.0;
            String key = "chart-" + time + "-" + session.getId() + "-" + random;
            session.setAttribute(key, chart);

            pageContext.getOut()
                    .write("<img src=\"" + request.getContextPath() + "/" + SERVLET_NAME + "?" + CHART_KEY + "="
                            + key + "&mimeType=" + PNG_MIME_TYPE + "&width=" + width + "&height=" + height
                            + "\" />");

        } catch (IOException e) {
            log.error("Unable to generate chart servlet url", e);
        }
    }

    return EVAL_BODY_BUFFERED;
}

From source file:org.mt4jx.components.visibleComponents.widgets.jfreechart.examples.MTJFreeChartExampleScene.java

public MTJFreeChartExampleScene(MTApplication mtApplication, String name) {
    super(mtApplication, name);
    this.setClearColor(new MTColor(0, 0, 96, 255));
    //Show touches
    this.registerGlobalInputProcessor(new CursorTracer(mtApplication, this));

    // Create Example Data
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (int i = 0; i < 10; i++) {
        dataset.addValue(10 * Math.random(), "MySeries", "T" + i);
    }/* w ww. j a v  a2  s .c om*/
    // Create a JFreeChart
    JFreeChart chart1 = ChartFactory.createLineChart("Line Chart", "x axis", "y axis", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    // Put the JFreeChart into a MTJFreeChart wrapper
    MTJFreeChart mtChart1 = new MTJFreeChart(800, 600, mtApplication, chart1);

    // Create another chart
    DefaultPieDataset pds = new DefaultPieDataset();

    pds.setValue("Java", new Double(17.773));
    pds.setValue("C", new Double(15.822));
    pds.setValue("C++", new Double(8.783));
    pds.setValue("PHP", new Double(7.835));
    pds.setValue("Python", new Double(6.265));
    pds.setValue("C#", new Double(6.226));
    pds.setValue("(Visual) Basic", new Double(5.867));
    pds.setValue("Objective-C", new Double(3.011));
    pds.setValue("Perl", new Double(2.857));

    JFreeChart chart2 = ChartFactory.createPieChart3D(
            "Top 10: TIOBE Programming Community Index\nfor January 2011 (www.tiobe.com)", pds, true, true,
            Locale.GERMANY);
    PiePlot3D plot = (PiePlot3D) chart2.getPlot();
    plot.setStartAngle(290);

    MTJFreeChart mtChart2 = new MTJFreeChart(800, 600, mtApplication, chart2);
    // enable redraw of the chart when it's scaled by the user
    mtChart2.setRedrawWhenScaled(true);
    this.getCanvas().addChild(mtChart1);
    this.getCanvas().addChild(mtChart2);
    mtChart1.setPositionGlobal(new Vector3D(mtApplication.width / 2f, mtApplication.height / 2f));
    mtChart2.setPositionGlobal(new Vector3D(150 + mtApplication.width / 2f, 150 + mtApplication.height / 2f));
}

From source file:com.microsoft.office.integration.test.FoldersTestCase.java

public void testMoveAndCopy() {
    final String name = "move and copy test" + (int) (Math.random() * 1000000);
    folder = Me.getRootFolder().getChildFolders().newFolder();
    folder.setDisplayName(name);//from   w ww . ja v  a 2  s.co  m
    IFolder copied = null;
    folder = folder.move(Me.getDrafts().getId());
    copied = folder.copy(Me.getRootFolder().getId());

    Me.getFolders().delete(folder.getId());
    if (copied != null) {
        Me.getFolders().delete(copied.getId());
    }

    Me.flush();
}

From source file:com.codestudio.dorm.web.support.spring.upload.FileUploadSupport.java

public Attachment upload(long userId, byte[] file, String type, String uuid) {
    if (StringUtils.isBlank(type)) {
        type = DEFAULT_TYPE;/*from   w w w. j a  va 2 s  . c o  m*/
    }
    if (file == null) {
        return null;
    }

    FileOutputStream fs = null;
    InputStream is = null;
    try {
        is = new ByteArrayInputStream(file);

        String ext = ".png";
        Date now = new Date();
        String filePath = "/" + type + "/"
                + DateUtils.dateConvert2String(now, DateUtils.DATEPATTERN_YYYY_MM_DD4FILE) + "/";

        String fileName = now.getTime() + "" + ((int) (Math.random() * 10));

        File f = new File(uploadFilePath + filePath);
        if (!f.exists()) {
            f.mkdirs();
        }
        fs = new FileOutputStream(uploadFilePath + filePath + fileName + ext);
        byte[] buffer = new byte[1024 * 1024];
        int byteread = 0;
        while ((byteread = is.read(buffer)) != -1) {
            fs.write(buffer, 0, byteread);
            fs.flush();
        }

        // ???
        Attachment attachment = new Attachment();
        attachment.setSrcName(null);
        attachment.setDescName(fileName);
        attachment.setFileType(type);
        attachment.setExt(ext);
        attachment.setPath(filePath);
        attachment.setSize(file.length + 0L);
        attachment.setUserId(userId);
        attachment.setUuid(uuid);
        attachmentService.add(attachment);
        return attachment;
    } catch (Exception e) {
        logger.error("upload file error:", e);
    } finally {
        try {
            fs.close();
            is.close();
        } catch (Exception e) {
            logger.error("close file error:", e);
        }
    }
    return null;
}

From source file:cn.ipanel.apps.portalBackOffice.util.CommonsFiend.java

public static int getRandom(int max) {
    return (int) (Math.random() * (double) max);
}