List of usage examples for java.lang Math random
public static double random()
From source file:sf.wicketlearningapplication.server.TestUtility.java
public static Bug createNewBugInstance() { final int estimatedHours = random.nextInt(8) + 1; final Severity severity = Severity.values()[(int) (Math.random() * Severity.values().length)]; final Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DAY_OF_MONTH, random.nextInt(30)); ////w ww .jav a 2 s . c o m final Bug bug = new Bug(); bug.setSummary(text()); bug.setSeverity(severity); bug.setEstimatedHours(estimatedHours); bug.setDueByDate(calendar.getTime()); return bug; }
From source file:org.esigate.url.StickySessionBaseUrlRetrieveStrategy.java
private int generateIndex() { return (int) (Math.random() * this.urls.length); }
From source file:br.ifes.poo2.chess.cln.cdp.players.factories.PlayerComputer.java
public String play(Color color, Game game) { Iterator<Piece> iterator = game.getPiecesOfPlayer(color); List<Piece> listOfPieces = IteratorUtils.toList(iterator); List<Position> positions; int rand;/*w w w. j av a 2 s . c o m*/ Piece piece; Position positionAux; int count = 0; while (count < 50) { if (listOfPieces.size() > 0) { rand = (int) (Math.random() * (listOfPieces.size() - 1)); piece = listOfPieces.get(rand); positions = piece.getPath(game.getChessBoard(), piece.getPosition()); if (positions.size() > 0) { rand = (int) (Math.random() * (positions.size() - 1)); positionAux = positions.get(rand); return "" + piece.getPosition().getColumn() + piece.getPosition().getLine() + positionAux.getColumn() + positionAux.getLine(); } } count++; } return "desistir"; }
From source file:org.pikax.log.generator.process.v1.CheckPaymentDelegate.java
@Override public void doExecute(final DelegateExecution execution) throws Exception { final double seed = Math.random(); if (seed < 0.2) { execution.setVariable("payment", "notok"); } else {/* w w w. jav a2 s . c o m*/ execution.setVariable("payment", "ok"); } }
From source file:dtu.ds.warnme.utils.RandomUtils.java
public static int randomInt(int min, int max) { return (int) (min + Math.random() * (max - min + 1)); }
From source file:org.pikax.log.generator.process.v1.ProcessClaimDelegate.java
@Override public void doExecute(final DelegateExecution execution) throws Exception { final double seed = Math.random(); if (seed < 0.2) { execution.setVariable("claim", "rejected"); } else if (seed < 0.72) { execution.setVariable("claim", "ok"); } else {/*w w w . j a v a 2 s . co m*/ execution.setVariable("claim", "behind"); } }
From source file:com.falkonry.TestAddFactsStream.java
/** * Should create datastream and add fact stream data in CSV format * @throws Exception/* ww w. j a v a 2 s . c o m*/ */ @Test public void createDatastreamWithCsvFactsStream() throws Exception { Datastream ds = new Datastream(); ds.setName("Test-DS-" + Math.random()); TimeObject time = new TimeObject(); time.setIdentifier("time"); time.setFormat("iso_8601"); time.setZone("GMT"); Signal signal = new Signal(); signal.setTagIdentifier("tag"); signal.setValueIdentifier("value"); signal.setDelimiter("_"); signal.setIsSignalPrefix(false); Field field = new Field(); field.setSiganl(signal); field.setTime(time); ds.setField(field); Datasource dataSource = new Datasource(); dataSource.setType("STANDALONE"); ds.setDatasource(dataSource); Datastream datastream = falkonry.createDatastream(ds); datastreams.add(datastream); List<Assessment> assessments = new ArrayList<Assessment>(); AssessmentRequest assessmentRequest = new AssessmentRequest(); assessmentRequest.setName("Health"); assessmentRequest.setDatastream(datastream.getId()); assessmentRequest.setAssessmentRate("PT1S"); Assessment assessment = falkonry.createAssessment(assessmentRequest); assessments.add(assessment); Map<String, String> options = new HashMap<String, String>(); String data = "time, tag, value\n2016-03-01 01:01:01, entity1_signal1, 3.4"; falkonry.addInput(datastream.getId(), data, options); File file = new File("res/factsData.csv"); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(FileUtils.readFileToByteArray(file)); InputStatus response = falkonry.addFactsStream(assessment.getId(), byteArrayInputStream, null); Assert.assertEquals(response.getAction(), "ADD_FACT_DATA"); Assert.assertEquals(response.getStatus(), "PENDING"); }
From source file:de.undercouch.citeproc.script.ScriptRunnerBenchmark.java
/** * Set up this test/*from w w w. ja va 2 s . c om*/ * @throws Exception if something goes wrong */ @BeforeClass public static void setUp() throws Exception { db = loadUnixDatabase(); sys.addDatabase(db); for (int i = 0; i < 10; ++i) { int j = (int) (Math.random() * db.getEntries().size()); rnds.add(j); } }
From source file:com.linkedin.pinot.common.utils.KafkaStarterUtils.java
public static List<KafkaServerStartable> startServers(final int brokerCount, final int port, final String zkStr, final Properties configuration) { List<KafkaServerStartable> startables = new ArrayList<>(brokerCount); for (int i = 0; i < brokerCount; i++) { startables.add(startServer(port + i, i, zkStr, "/tmp/kafka-" + Double.toHexString(Math.random()), configuration));//w w w . j a va2 s . c o m } return startables; }
From source file:com.jennifer.ui.util.StringUtil.java
public static String createId(String key) { return key + "-" + System.currentTimeMillis() + "-" + (Math.round(Math.random() * 100) % 100); }