List of usage examples for java.lang Math random
public static double random()
From source file:com.mgmtp.perfload.core.client.util.BetaDistWaitingTimeStrategy.java
@Override public long calculateWaitingTime() { BetaDistribution betaDist = new BetaDistribution(betaDistParamA, betaDistParamB); double probability = betaDist.cumulativeProbability(Math.random()); return calculateNormedValue(probability); }
From source file:com.mycompany.internalservicecontrollerbatch.ServerCall.java
@Override public void run() { String url = list.getCallToPerform(); try {//from w ww . j a va 2s . co m HttpClient client = HttpClientBuilder.create().build(); if (url != null) { //HttpPost post = new HttpPost(url); //StringEntity entity = new StringEntity(""); //post.setEntity(entity); HttpGet request = new HttpGet(url); long start = System.currentTimeMillis(); HttpResponse response = client.execute(request); long end = System.currentTimeMillis(); //System.out.println("Response Code : "+ response.getStatusLine().getStatusCode() + " index: " +index + " start: " + start + " end: " +end+ " thread name: "+ Thread.currentThread().getName()); double r = Math.random(); long wait = Math.round(r * 250); HttpEntity entity = response.getEntity(); String responseString = EntityUtils.toString(entity, "UTF-8"); String printout = "Server Call: " + url + " Response Code : " + response.getStatusLine().getStatusCode() + " Response content: " + responseString; list.resolveCall(printout, true); Thread.sleep(wait); } } catch (Exception ex) { Logger.getLogger(ServerCall.class.getName()).log(Level.SEVERE, null, ex); list.resolveCall("ERROR PERFORMING: " + url, false); } }
From source file:com.splout.db.dnode.TestFetcher.java
@Test public void testThrottling() throws InterruptedException { double bytesPerSec = 1000; Throttler throttler = new Throttler(bytesPerSec); long startTime = System.currentTimeMillis(); int bytesConsumed = 0; for (int i = 0; i < 10; i++) { int bytes = (int) (Math.random() * 1000); bytesConsumed += bytes;// w ww .j a v a 2s . c o m throttler.incrementAndThrottle(bytes); } long endTime = System.currentTimeMillis(); double secs = (endTime - startTime) / (double) 1000; double avgBytesPerSec = bytesConsumed / secs; assertEquals(bytesPerSec, avgBytesPerSec, 5.0); // + - 5 }
From source file:com.appzone.sim.services.handlers.SendMoServiceHandler.java
@Override protected String doProcess(HttpServletRequest request) { String address = request.getParameter(KEY_ADDRESS); String message = request.getParameter(KEY_MESSAGE); String correlator = "" + ((int) (Math.random() * 10000000000000L)); try {/*from w w w . ja va2s . co m*/ String queryString = String.format("version=1.0&address=%s&message=%s&correlator=%s", address, URLEncoder.encode(message, "UTF-8"), URLEncoder.encode(correlator, "UTF-8")); logger.info("sending MO request as: {}", queryString); String response = http.excutePost(application.getUrl(), queryString); logger.debug("getting response as: {}", response); JSONObject json = new JSONObject(); json.put(ServiceHandler.JSON_KEY_RESULT, response); return json.toJSONString(); } catch (Exception e) { logger.error("Error while sending http request", e); JSONObject json = new JSONObject(); json.put(ServiceHandler.JSON_KEY_ERROR, e.getMessage()); return json.toJSONString(); } }
From source file:com.victor.fishhub.service.ratioalgo.FishRatioImpl.java
private Integer getRatioValue(H3PeriodWeather h3, Fish fish) { Integer ratio = null;/* w w w . j a v a 2s . c o m*/ if (h3 != null && fish != null) { ratio = (int) ((h3.getTemperature() / 25) * 5 + Math.random() * 5); ratio = ratio > 10 ? 10 : ratio; } return ratio; }
From source file:ar.org.neuroph.core.Weight.java
/** * Creates an instance of connection weight with random weight value in * range [0..1]// ww w. j a v a2s . c o m */ public Weight() { this.value = Math.random() - 0.5d; this.weightChange = 0; }
From source file:org.eclipse.swt.examples.graphics.IntroTab.java
@Override public void next(int width, int height) { x += incX;/* w w w . jav a 2s. co m*/ y += incY; float random = (float) Math.random(); if (x + textWidth > width) { x = width - textWidth; incX = random * -width / 16 - 1; } if (x < 0) { x = 0; incX = random * width / 16 + 1; } if (y + textHeight > height) { y = (height - textHeight) - 2; incY = random * -height / 16 - 1; } if (y < 0) { y = 0; incY = random * height / 16 + 1; } }
From source file:ByteFIFOTest.java
private void src() { try {/*from www . ja v a 2s . c o m*/ boolean justAddOne = true; int count = 0; while (count < srcData.length) { if (!justAddOne) { int writeSize = (int) (40.0 * Math.random()); writeSize = Math.min(writeSize, srcData.length - count); byte[] buf = new byte[writeSize]; System.arraycopy(srcData, count, buf, 0, writeSize); fifo.add(buf); count += writeSize; System.out.println("just added " + writeSize + " bytes"); } else { fifo.add(srcData[count]); count++; System.out.println("just added exactly 1 byte"); } justAddOne = !justAddOne; } } catch (InterruptedException x) { x.printStackTrace(); } }
From source file:edu.umass.cs.reconfiguration.reconfigurationpackets.StopEpoch.java
/** * @param initiator/*from w w w.j av a 2s. c o m*/ * @param name * @param epochNumber * @param getFinalState * @param executeStop */ public StopEpoch(NodeIDType initiator, String name, int epochNumber, boolean getFinalState, boolean executeStop) { super(initiator, ReconfigurationPacket.PacketType.STOP_EPOCH, name, epochNumber); this.getFinalState = getFinalState; this.requestID = (long) (Math.random() * Long.MAX_VALUE); this.executeStop = executeStop; }
From source file:com.commenterteam.commenter.controller.AppController.java
@RequestMapping("/place/{placeId}/user/{userId}") public String indexHandler(Model model, @PathVariable("placeId") String placeId, @PathVariable("userId") String userId) { Place place = placeService.getPlaceById(Integer.valueOf(placeId)); model.addAttribute("place", place); int approve = (int) (Math.random() * 100); model.addAttribute("approve", approve); return "index"; }