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:com.apress.prospringintegration.springenterprise.stocks.transactions.template.TransactionalStockBrokerService.java

public void preFillStocks(final String exchangeId, final String... symbols) {
    final Random random = new Random();

    transactionTemplate.execute(new TransactionCallbackWithoutResult() {
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            int i = 0;
            for (String sym : symbols) {
                float pp = (float) Math.random() * 100.0f;
                int qq = (int) Math.random() * 250;
                Stock s = new Stock(sym, "INV00" + i, exchangeId, pp, qq, Calendar.getInstance().getTime());
                stockDao.insert(s);/*w w w.  j  av a 2 s  . c  o  m*/
                System.out.println("ORIG INVENTORY: " + s.getInventoryCode() + " ");
                int randomized = (random.nextInt(100) % 4) == 0 ? 0 : i;
                s.setInventoryCode("INV00" + randomized);
                System.out.println("NEW RANDOMIZED INVENTORY:" + s.getInventoryCode() + " " + randomized);
                stockDao.update(s);
                i++;
            }
        }
    });
}

From source file:com.acme.spring.inject.repository.impl.DefaultStockRepository.java

/**
 * {@inheritDoc}//from  w w w  .  ja va2  s  .  c om
 */
@Override
public long save(Stock stock) {

    validateNoNull(stock, "stock");
    validateNotEmpty(stock.getSymbol(), "symbol");

    // generates 'unique' identifier
    stock.setId((long) (Math.random() * 10E4D));

    // saves the stock in map
    stockMap.put(stock.getSymbol(), stock);

    // returns the assigned id
    return stock.getId();
}

From source file:jp.primecloud.auto.ui.mock.service.MockFarmService.java

@Override
public Long createFarm(Long userNo, String farmName, String comment) {
    Long farmNo = (long) (Math.random() * 100);
    log.info(MessageUtils.format("Create farm.(farmNo={0})", farmNo));
    return farmNo;
}

From source file:com.microsoft.office.core.FoldersTestCase.java

@Test
public void moveAndCopyTest() {
    final String name = "move and copy test" + (int) (Math.random() * 1000000);
    folder = Me.getRootFolder().getChildFolders().newFolder();
    folder.setDisplayName(name);//from w  w  w  .j ava  2s  . c  om
    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:edu.umass.cs.reconfiguration.reconfigurationpackets.DemandReport.java

/**
 * @param initiator/*from  ww  w.  j  a va 2s . c  om*/
 * @param name
 * @param epochNumber
 * @param demand
 */
public DemandReport(NodeIDType initiator, String name, int epochNumber, AbstractDemandProfile demand) {
    super(initiator, ReconfigurationPacket.PacketType.DEMAND_REPORT, name, epochNumber);
    this.stats = demand.getStats();
    this.requestID = (long) (Math.random() * Long.MAX_VALUE);
}

From source file:Main.java

@Override
public void start(Stage stage) {
    final NumberAxis xAxis = new NumberAxis();
    final CategoryAxis yAxis = new CategoryAxis();
    final BarChart<Number, String> bc = new BarChart<Number, String>(xAxis, yAxis);
    bc.setTitle("Summary");
    xAxis.setLabel("Value");
    xAxis.setTickLabelRotation(90);/*ww  w.j  a  v  a  2 s .co  m*/
    yAxis.setLabel("Item");

    XYChart.Series series1 = new XYChart.Series();
    series1.setName("2003");
    series1.getData().add(new XYChart.Data(2, itemA));
    series1.getData().add(new XYChart.Data(20, itemB));
    series1.getData().add(new XYChart.Data(10, itemC));

    XYChart.Series series2 = new XYChart.Series();
    series2.setName("2004");
    series2.getData().add(new XYChart.Data(50, itemA));
    series2.getData().add(new XYChart.Data(41, itemB));
    series2.getData().add(new XYChart.Data(45, itemC));

    XYChart.Series series3 = new XYChart.Series();
    series3.setName("2005");
    series3.getData().add(new XYChart.Data(45, itemA));
    series3.getData().add(new XYChart.Data(44, itemB));
    series3.getData().add(new XYChart.Data(18, itemC));

    Timeline tl = new Timeline();
    tl.getKeyFrames().add(new KeyFrame(Duration.millis(500), new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent actionEvent) {
            for (XYChart.Series<Number, String> series : bc.getData()) {
                for (XYChart.Data<Number, String> data : series.getData()) {
                    data.setXValue(Math.random() * 100);
                }
            }
        }
    }));
    tl.setCycleCount(Animation.INDEFINITE);
    tl.play();

    Scene scene = new Scene(bc, 800, 600);
    bc.getData().addAll(series1, series2, series3);
    stage.setScene(scene);
    stage.show();
}

From source file:org.eclipse.swt.examples.graphics.FontBounceTab.java

@Override
public void next(int width, int height) {
    x += incX;//  w  w w  .  j ava 2  s. c  o m
    y += incY;
    float random = (float) Math.random();

    // collision with right side of screen
    if (x + textWidth > width) {
        x = width - textWidth;
        incX = random * -width / 16 - 1;
        fontFace = 0;
        fontSize = 125;
        fillColor = SWT.COLOR_DARK_BLUE;
        foreGrdColor = SWT.COLOR_YELLOW;
        fontStyle = SWT.ITALIC;
    }
    // collision with left side of screen
    if (x < 0) {
        x = 0;
        incX = random * width / 16 + 1;
        fontFace = 1;
        fontSize = 80;
        fillColor = SWT.COLOR_DARK_MAGENTA;
        foreGrdColor = SWT.COLOR_CYAN;
        fontStyle = SWT.NONE;
    }
    // collision with bottom side of screen
    if (y + textHeight > height) {
        y = (height - textHeight) - 2;
        incY = random * -height / 16 - 1;
        fontFace = 2;
        fontSize = 100;
        fillColor = SWT.COLOR_YELLOW;
        foreGrdColor = SWT.COLOR_BLACK;
        fontStyle = SWT.BOLD;
    }
    // collision with top side of screen
    if (y < 0) {
        y = 0;
        incY = random * height / 16 + 1;
        fontFace = 3;
        fontSize = 120;
        fillColor = SWT.COLOR_GREEN;
        foreGrdColor = SWT.COLOR_GRAY;
        fontStyle = SWT.NONE;
    }
}

From source file:us.putney.controllers.SampleServiceController.java

static Map getPower() {
    Map<String, Object> power = new HashMap<String, Object>();
    power.put("name", powers[(int) Math.floor(Math.random() * powers.length)]);
    power.put("level", (int) (Math.random() * 10));
    return power;
}

From source file:IK.G.java

public static double random(double a, double b) {
    return a + ((abs(a - b)) * Math.random());
}

From source file:io.starter.TestReact.java

public JSONObject getJSON() {
    JSONObject dtx = new JSONObject();

    dtx.put("name", "Object 2");
    dtx.put("description", "Test Object Number Two");

    // set a url//from w  w  w .  ja v  a  2s. com
    String urx = "/table_view.jsp?tablename=User&query=id:";
    dtx.put("url", urx);

    // add children
    JSONArray jarr = new JSONArray();
    for (int t = 0; t < 5; t++) {
        JSONObject jab = new JSONObject();
        jab.put("name", "Location " + t);
        jab.put("latitude", (t * (430 * Math.random())) + "." + Math.random());
        jab.put("longitude", (t * (1300 * Math.random())) + "." + Math.random());

        jarr.put(jab);
    }

    dtx.put("locations", jarr);

    return dtx;
}