List of usage examples for java.lang Math random
public static double random()
From source file:biz.fstechnology.micro.common.jms.RequestMessageCreator.java
/** * @see org.springframework.jms.core.MessageCreator#createMessage(javax.jms.Session) *//*from w w w . ja v a2s . c o m*/ @Override public Message createMessage(Session session) throws JMSException { ObjectMessage message = session.createObjectMessage(); message.setObject(getContents()); message.setJMSReplyTo(getReplyTo()); if (getRequestId() == null) { setRequestId(Double.toHexString(Math.random())); } message.setJMSCorrelationID(getRequestId()); return message; }
From source file:com.jnj.b2b.fulfilmentprocess.actions.consignment.SubprocessEndAction.java
@Override public void executeAction(final ConsignmentProcessModel process) { LOG.info("Process: " + process.getCode() + " in step " + getClass()); try {/* ww w. ja v a2 s .co m*/ // simulate different ending times Thread.sleep((long) (Math.random() * 2000)); } catch (final InterruptedException e) { // can't help it } process.setDone(true); save(process); LOG.info("Process: " + process.getCode() + " wrote DONE marker"); getBusinessProcessService().triggerEvent(process.getParentProcess().getCode() + "_" + Jnjb2bFulfilmentProcessConstants.CONSIGNMENT_SUBPROCESS_END_EVENT_NAME); LOG.info("Process: " + process.getCode() + " fired event " + Jnjb2bFulfilmentProcessConstants.CONSIGNMENT_SUBPROCESS_END_EVENT_NAME); }
From source file:com.apress.prospringintegration.springenterprise.stocks.transactions.aopdeclarative.AOPStockBrokerService.java
public void preFillStocks(final String exchangeId, final String... symbols) { int i = 0;/*from ww w . j a va 2 s . c om*/ 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); 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:org.training.fulfilmentprocess.actions.consignment.SubprocessEndAction.java
@Override public void executeAction(final ConsignmentProcessModel process) { LOG.info("Process: " + process.getCode() + " in step " + getClass()); try {// w w w. j a v a 2 s . c o m // simulate different ending times Thread.sleep((long) (Math.random() * 2000)); } catch (final InterruptedException e) { // can't help it } process.setDone(true); save(process); LOG.info("Process: " + process.getCode() + " wrote DONE marker"); getBusinessProcessService().triggerEvent(process.getParentProcess().getCode() + "_" + TrainingFulfilmentProcessConstants.CONSIGNMENT_SUBPROCESS_END_EVENT_NAME); LOG.info("Process: " + process.getCode() + " fired event " + TrainingFulfilmentProcessConstants.CONSIGNMENT_SUBPROCESS_END_EVENT_NAME); }
From source file:org.vinmonopolet.fulfilmentprocess.actions.consignment.SubprocessEndAction.java
@Override public void executeAction(final ConsignmentProcessModel process) { LOG.info("Process: " + process.getCode() + " in step " + getClass()); try {/* w w w .j a v a 2s . c o m*/ // simulate different ending times Thread.sleep((long) (Math.random() * 2000)); } catch (final InterruptedException e) { // can't help it } process.setDone(true); save(process); LOG.info("Process: " + process.getCode() + " wrote DONE marker"); getBusinessProcessService().triggerEvent(process.getParentProcess().getCode() + "_" + VinmonopoletFulfilmentProcessConstants.CONSIGNMENT_SUBPROCESS_END_EVENT_NAME); LOG.info("Process: " + process.getCode() + " fired event " + VinmonopoletFulfilmentProcessConstants.CONSIGNMENT_SUBPROCESS_END_EVENT_NAME); }
From source file:eu.fusepool.tests.RoundTripTest.java
@Test public void fromDlcToEcs() { final String dataSetLabel = "test" + (Math.round(Math.random() * 10000)); //Create DataSet RestAssured.given().auth().basic("admin", "admin").formParam("pipe_label", dataSetLabel).redirects() .follow(false).expect().statusCode(HttpStatus.SC_SEE_OTHER).when().post("/sourcing/create_pipe"); //ISSUE: the above doesn't return the name of the created dataset final String dataSetName = "urn:x-localinstance:/dlc/" + dataSetLabel; RestAssured.given().auth().basic("admin", "admin").expect().body(containsString(INTERLINKER_NAME)).when() .get("/sourcing/"); //Start batch processing final Response processBatchResponse = RestAssured.given().redirects().follow(false).auth() .basic("admin", "admin").formParam("dataSet", dataSetName).formParam("rdfizer", "patent") .formParam("digester", "patent").formParam("interlinker", INTERLINKER_NAME) .formParam("skipPreviouslyAdded", "on").formParam("smushAndPublish", "on") .formParam("recurse", "on").formParam("maxFiles", "2") .formParam("url", "http://raw.fusepool.info/IREC/EP/").expect().statusCode(HttpStatus.SC_SEE_OTHER) .when().post("/sourcing/processBatch/"); //ISSUE: the task is started without checking if the dataset and interlinker exists final String taskLocation = processBatchResponse.getHeader("Location"); //Making sure the tasks ends after a while int i = 0;//from w w w.jav a2s. co m while (true) { if (i++ == 120) { throw new RuntimeException("Did not end after two minutes: " + taskLocation); } try { Thread.sleep(1000); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } final Response taskResponse = RestAssured.given().header("Accept", "text/html").expect() .body(containsString("started")).get(taskLocation); if (taskResponse.getBody().asString().contains("ended")) { break; } } //it may take a while till the data is reindex and available in ECS Graph graph; i = 0; while (true) { //now ecs should find some data final Response ecsResponse = RestAssured.given().header("Accept", "text/turtle") .queryParam("search", "*").expect().statusCode(HttpStatus.SC_OK) .header("Content-Type", "text/turtle").when().get("/ecs/"); graph = Parser.getInstance().parse(new ByteArrayInputStream(ecsResponse.asByteArray()), SupportedFormat.TURTLE); if (graph.size() > 10) { break; } if (i == 150) { log.warn("Did not find triples in ECS after 4 minutes! Now triggering reindexing via HTTP call."); RestAssured.given().auth().basic("admin", "admin").expect().statusCode(HttpStatus.SC_OK) .body(containsString("indexed")).when().get("/ecs/reindex"); } if (i++ == 190) { throw new RuntimeException("Did not find triples in ECS result even after 8 minute"); } try { if (i >= 100) { Thread.sleep(4000); } else { Thread.sleep(400); } } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } } //Assert.assertTrue("The graph returned by ecs seems too small (only " + graph.size() + " triples)", graph.size() > 10); GraphNode storeViewType = new GraphNode(ECS.ContentStoreView, graph); GraphNode storeView = storeViewType.getSubjectNodes(RDF.type).next(); Literal contentsCount = storeView.getLiterals(ECS.contentsCount).next(); Assert.assertTrue("No content found.", Integer.parseInt(contentsCount.getLexicalForm()) > 0); }
From source file:com.exxonmobile.ace.hybris.fulfilmentprocess.actions.consignment.SubprocessEndAction.java
@Override public void executeAction(final ConsignmentProcessModel process) { LOG.info("Process: " + process.getCode() + " in step " + getClass()); try {// www . j a v a2s . com // simulate different ending times Thread.sleep((long) (Math.random() * 2000)); } catch (final InterruptedException e) { // can't help it } process.setDone(true); save(process); LOG.info("Process: " + process.getCode() + " wrote DONE marker"); getBusinessProcessService().triggerEvent(process.getParentProcess().getCode() + "_" + ExxonmobilFulfilmentProcessConstants.CONSIGNMENT_SUBPROCESS_END_EVENT_NAME); LOG.info("Process: " + process.getCode() + " fired event " + ExxonmobilFulfilmentProcessConstants.CONSIGNMENT_SUBPROCESS_END_EVENT_NAME); }
From source file:mtsar.processors.task.FixedNumberAllocator.java
@Override protected List<Integer> filterTasks(Map<Integer, Integer> counts) { checkAnswersPerTask();/* w w w . jav a 2s . com*/ return counts.entrySet().stream().filter(entry -> entry.getValue() < answersPerTask) .map(entry -> Triple.of(entry.getKey(), entry.getValue(), Math.random())).sorted(INVERSE_COUNT) .map(Triple::getLeft).collect(Collectors.toList()); }
From source file:com.example.ExampleController.java
@RequestMapping("/meet") public String meet() throws InterruptedException { long duration = 200L + (long) (Math.random() * 500L); Thread.sleep(duration);/* w ww . ja v a2 s. c o m*/ LOGGER.info("meeting took " + duration + "ms"); return "meeting finished in " + duration + "ms"; }
From source file:com.certus.actions.uploadSliderImageAction.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String path = getServletContext().getRealPath("img/slider").replace("build/", ""); boolean isMultipart = ServletFileUpload.isMultipartContent(request); if (isMultipart) { FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); try {//from w w w . jav a 2 s . c o m List<FileItem> multiparts = upload.parseRequest(request); StringBuilder sb = null; for (FileItem item : multiparts) { if (!item.isFormField()) { double randomA = Math.random() * 1000000000; int randA = (int) randomA; String name = new File(item.getName()).getName(); sb = new StringBuilder(name); sb.replace(0, name.length() - 4, "slider-" + randA); item.write(new File(path + File.separator + sb)); } } String pathTo = path + File.separator + sb; response.getWriter().write(pathTo.substring(pathTo.lastIndexOf("img"))); } catch (Exception e) { e.printStackTrace(); } } }