List of usage examples for java.lang Math random
public static double random()
From source file:it.infn.ct.futuregateway.apiserver.utils.TestDataIT.java
/** * Create a random infrastructure.// www. j ava2 s .co m * All data are randomly generated but the infrastructure which is not * included. * * @return The infrastructure */ public static Application createApplication() { Application app = new Application(); app.setName(RandomStringUtils.randomAlphanumeric((int) (1 + (Math.random() * MAX_STRING_LENGTH)))); app.setDescription(RandomStringUtils.randomAlphanumeric((int) (1 + (Math.random() * MAX_DESC_LENGTH)))); app.setEnabled(rnd.nextBoolean()); List<Params> params = (List<Params>) new LinkedList<Params>(); for (int i = 0; i < (int) (Math.random() * MAX_ENTITIES_IN_LIST); i++) { Params p = new Params(); p.setDescription(RandomStringUtils.randomAlphanumeric((int) (1 + (Math.random() * MAX_DESC_LENGTH)))); p.setName(RandomStringUtils.randomAlphanumeric((int) (1 + (Math.random() * MAX_STRING_LENGTH)))); p.setValue(RandomStringUtils.randomAlphanumeric((int) (1 + (Math.random() * MAX_STRING_LENGTH)))); params.add(p); } if (!params.isEmpty()) { app.setParameters(params); } return app; }
From source file:org.jfree.chart.demo.PerformanceTest1.java
public static void main4(String as[]) { TimeSeries timeseries = new TimeSeries("Test"); timeseries.setMaximumItemCount(4000); FixedMillisecond fixedmillisecond = new FixedMillisecond(); for (int i = 0; i < 40000; i++) { long l = System.currentTimeMillis(); for (int j = 0; j < 400; j++) { fixedmillisecond = (FixedMillisecond) fixedmillisecond.next(); timeseries.add(fixedmillisecond, Math.random()); }//from ww w .ja va 2 s . c om long l1 = System.currentTimeMillis(); System.out.println(i + " --> " + (l1 - l) + " (" + Runtime.getRuntime().freeMemory() + " / " + Runtime.getRuntime().totalMemory() + ")"); } }
From source file:com.garyclayburg.UserRestSmokeTest.java
@Test public void testHalJsonApache() throws Exception { RestTemplate rest = new RestTemplate(new HttpComponentsClientHttpRequestFactory()); SimpleUser user1 = new SimpleUser(); user1.setFirstname("Tommy"); user1.setLastname("Deleteme"); user1.setId("112" + (int) (Math.floor(Math.random() * 10000))); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.set("Content-Type", "application/hal+json"); // HttpEntity<?> requestEntity = new HttpEntity(requestHeaders); HttpEntity<?> requestEntity = new HttpEntity(user1, requestHeaders); ResponseEntity<SimpleUser> simpleUserResponseEntity = rest.exchange( "http://" + endpoint + "/audited-users/auditedsave", HttpMethod.POST, requestEntity, SimpleUser.class); // ResponseEntity<SimpleUser> userResponseEntity = // rest.postForEntity("http://" + endpoint + "/audited-users/auditedsave",user1,SimpleUser.class); log.info("got a response"); MatcherAssertionErrors.assertThat(simpleUserResponseEntity.getStatusCode(), Matchers.equalTo(HttpStatus.OK)); }
From source file:gr.forth.ics.isl.x3mlEditor.upload.RequestParser.java
private String createUniqueFilename(String filename) { //Create a pseudorandom number long randomNumber = Math.round(Math.random() * 14000); Utils utils = new Utils(); String datestamp = utils.getDate(); String timestamp = utils.getTime(); String justName = filename.substring(0, filename.lastIndexOf('.')); String fileExtension = filename.substring(filename.lastIndexOf('.') + 1); //And use all of the above parts to create a unique random file name //var uniquename = results[0] + timestamp + datestamp + random +"." + results[1]; String uniquename = justName + "___" + datestamp + timestamp + "___" + randomNumber + "." + fileExtension; return uniquename; }
From source file:com.reelfx.controller.MacController.java
@Override public void setupExtensions() { //super.setupExtensions(); try {/*from www . ja v a 2 s .co m*/ /* might revisit copying the jar locally later if(!MAC_EXEC.exists() && Applet.DEV_MODE) { Applet.copyFolderFromRemoteJar(new URL("jar", "", "/Users/daniel/Documents/Java/java-review-tool/lib"+File.separator+"bin-mac.jar" + "!/"), "bin-mac"); Runtime.getRuntime().exec("chmod 755 "+MAC_EXEC.getAbsolutePath()).waitFor(); if(!MAC_EXEC.exists()) throw new IOException("Did not copy VLC to its execution directory!"); } else */ if (!Applet.BIN_FOLDER.exists()) { // delete any old versions for (File file : Applet.BASE_FOLDER.listFiles()) { if (file.getName().startsWith("bin") && file.isDirectory()) { FileUtils.deleteDirectory(file); if (file.exists()) throw new Exception("Could not delete the old native extentions!"); } } // download an install the new one String url = Applet.HOST_URL + File.separator + Applet.getBinFolderName() + ".jar?" + Math.random() * 10000; Applet.copyFolderFromRemoteJar(new URL(url), Applet.getBinFolderName()); if (!Applet.BIN_FOLDER.exists()) { logger.info("Could not find native extensions at " + url + ". Trying code base url..."); url = Applet.CODE_BASE.toString() + File.separator + Applet.getBinFolderName() + ".jar?" + Math.random() * 10000; Applet.copyFolderFromRemoteJar(new URL(url), Applet.getBinFolderName()); if (!Applet.BIN_FOLDER.exists()) { logger.info("Could not find native extensions at " + url + ". Trying document base url..."); url = Applet.DOCUMENT_BASE.toString() + File.separator + Applet.getBinFolderName() + ".jar?" + Math.random() * 10000; Applet.copyFolderFromRemoteJar(new URL(url), Applet.getBinFolderName()); if (!Applet.BIN_FOLDER.exists()) { throw new IOException( "Did not copy Mac extensions to the execution directory! Last url: " + url); } } } Runtime.getRuntime().exec("chmod 755 " + Applet.BIN_FOLDER + File.separator + "mac-screen-recorder") .waitFor(); } logger.info("Have access to execution folder: " + Applet.BIN_FOLDER.getAbsolutePath()); setReadyStateBasedOnPriorRecording(); } catch (Exception e) { // possibilities: MalformedURL, InterruptedException, IOException Applet.sendViewNotification(ViewNotifications.FATAL, new MessageNotification("Error with install", "Sorry, an error occurred while installing the native extensions. Please contact an admin.")); logger.error("Could not install the native extensions", e); } if (Applet.IS_MAC && !System.getProperty("os.version").contains("10.6")) { Applet.sendViewNotification(ViewNotifications.FATAL, new MessageNotification("Sorry, Snow Leopard required.", "Sorry, this tool requires that you have Mac OS X 10.6 (Snow Leopard)")); } }
From source file:com.dsf.dbxtract.cdc.AppJournalDeleteTest.java
/** * Rigourous Test :-)//from w ww. j a v a2s . co m * * @throws Exception * in case of any error */ @Test(timeOut = 120000) public void testAppWithJournalDelete() throws Exception { final Config config = new Config(configFile); BasicDataSource ds = new BasicDataSource(); Source source = config.getDataSources().getSources().get(0); ds.setDriverClassName(source.getDriver()); ds.setUsername(source.getUser()); ds.setPassword(source.getPassword()); ds.setUrl(source.getConnection()); // prepara os dados Connection conn = ds.getConnection(); conn.createStatement().execute("truncate table test"); conn.createStatement().execute("truncate table j$test"); // Carrega os dados de origem PreparedStatement ps = conn.prepareStatement("insert into test (key1,key2,data) values (?,?,?)"); for (int i = 0; i < TEST_SIZE; i++) { if ((i % 100) == 0) { ps.executeBatch(); } ps.setInt(1, i); ps.setInt(2, i); ps.setInt(3, (int) Math.random() * 500); ps.addBatch(); } ps.executeBatch(); ps.close(); app = new App(config); app.start(); Assert.assertEquals(config.getHandlers().iterator().next().getStrategy(), JournalStrategy.DELETE); // Popula as tabelas de journal ps = conn.prepareStatement("insert into j$test (key1,key2) values (?,?)"); for (int i = 0; i < TEST_SIZE; i++) { if ((i % 500) == 0) { ps.executeBatch(); } ps.setInt(1, i); ps.setInt(2, i); ps.addBatch(); } ps.executeBatch(); ps.close(); while (true) { TimeUnit.MILLISECONDS.sleep(500); ResultSet rs = conn.createStatement().executeQuery("select count(*) from j$test"); if (rs.next()) { long count = rs.getLong(1); System.out.println("remaining journal rows: " + count); rs.close(); if (count == 0L) break; } } conn.close(); ds.close(); }
From source file:com.google.appinventor.buildserver.ProjectBuilder.java
/** * Creates a new directory beneath the system's temporary directory (as * defined by the {@code java.io.tmpdir} system property), and returns its * name. The name of the directory will contain the current time (in millis), * and a random number.//from ww w . j a v a2 s. co m * * <p>This method assumes that the temporary volume is writable, has free * inodes and free blocks, and that it will not be called thousands of times * per second. * * @return the newly-created directory * @throws IllegalStateException if the directory could not be created */ private static File createNewTempDir() { File baseDir = new File(System.getProperty("java.io.tmpdir")); String baseNamePrefix = System.currentTimeMillis() + "_" + Math.random() + "-"; final int TEMP_DIR_ATTEMPTS = 10000; for (int counter = 0; counter < TEMP_DIR_ATTEMPTS; counter++) { File tempDir = new File(baseDir, baseNamePrefix + counter); if (tempDir.exists()) { continue; } if (tempDir.mkdir()) { return tempDir; } } throw new IllegalStateException("Failed to create directory within " + TEMP_DIR_ATTEMPTS + " attempts (tried " + baseNamePrefix + "0 to " + baseNamePrefix + (TEMP_DIR_ATTEMPTS - 1) + ')'); }
From source file:plugins.tutorial.chart.ChartTutorial2.java
/** * Returns a sample dataset./* w w w.jav a 2 s . c o m*/ * * @return The dataset. */ private static XYDataset createDataset() { YIntervalSeries yintervalseries = new YIntervalSeries("Series 1"); YIntervalSeries yintervalseries1 = new YIntervalSeries("Series 2"); Object obj = new Week(); double d = 100D; double d1 = 100D; for (int i = 0; i <= 52; i++) { double d2 = 0.050000000000000003D * i; yintervalseries.add(((RegularTimePeriod) (obj)).getFirstMillisecond(), d, d - d2, d + d2); d = (d + Math.random()) - 0.45000000000000001D; double d3 = 0.070000000000000007D * i; yintervalseries1.add(((RegularTimePeriod) (obj)).getFirstMillisecond(), d1, d1 - d3, d1 + d3); d1 = (d1 + Math.random()) - 0.55000000000000004D; obj = ((RegularTimePeriod) (obj)).next(); } YIntervalSeriesCollection yintervalseriescollection = new YIntervalSeriesCollection(); yintervalseriescollection.addSeries(yintervalseries); yintervalseriescollection.addSeries(yintervalseries1); return yintervalseriescollection; }
From source file:com.splout.db.common.SploutClient.java
public Tablespace tablespace(String tablespace) throws IOException { HttpRequest request = requestFactory.buildGetRequest( new GenericUrl(qNodes[(int) (Math.random() * qNodes.length)] + "/api/tablespace/" + tablespace)); HttpResponse resp = request.execute(); try {/*from w w w . j ava 2 s. com*/ return JSONSerDe.deSer(asString(resp.getContent()), Tablespace.class); } catch (JSONSerDeException e) { throw new IOException(e); } }
From source file:com.alvermont.terraj.planet.PlanetParameters.java
/** Creates a new instance of PlanetParameters */ public PlanetParameters() { reset(); seed = Math.random(); }