List of usage examples for java.util Random nextFloat
public float nextFloat()
From source file:iSoron.HistoryChart.java
public void populateWithRandomData() { Random random = new Random(); checkmarks = new int[100]; for (int i = 0; i < 100; i++) if (random.nextFloat() < 0.3) checkmarks[i] = 2;/*from ww w.j av a 2 s. com*/ for (int i = 0; i < 100 - 7; i++) { int count = 0; for (int j = 0; j < 7; j++) if (checkmarks[i + j] != 0) count++; if (count >= 3) checkmarks[i] = Math.max(checkmarks[i], 1); } }
From source file:com.intranet.intr.inbox.EmpControllerInbox.java
@RequestMapping(value = "/Eajaxtest2", method = RequestMethod.GET) public @ResponseBody String getTime(Principal principal) { String name = principal.getName(); int numMensa = numCorreosNOL(name); String result = "" + numMensa; //System.out.println("ajaxtext"); Random rand = new Random(); float r = rand.nextFloat() * 100; //String result = "<br>Next Random # is <b>" + r + "</b>. Generated on <b>" + new Date().toString() + "</b>"; //System.out.println("Debug Message from CrunchifySpringAjaxJQuery Controller.." + new Date().toString()); return result; }
From source file:org.aksw.gerbil.database.ExperimentDAOImplJUnitTest.java
@Test public void testExperimentCreationAndSelection() throws InterruptedException { final String EXPERIMENT_ID = "id-999"; Set<ExperimentTaskResult> results = new HashSet<ExperimentTaskResult>(); Random random = new Random(); for (int i = 0; i < 10; ++i) { if (i < 8) { results.add(new ExperimentTaskResult("annotator1", "dataset" + i, ExperimentType.D2W, Matching.STRONG_ANNOTATION_MATCH, new double[] { random.nextFloat(), random.nextFloat(), random.nextFloat(), random.nextFloat(), random.nextFloat(), random.nextFloat() }, ExperimentDAO.TASK_FINISHED, random.nextInt())); } else {//from w ww . ja v a 2 s .com results.add(new ExperimentTaskResult("annotator1", "dataset" + i, ExperimentType.D2W, Matching.STRONG_ANNOTATION_MATCH, new double[6], i == 8 ? ExperimentDAO.TASK_STARTED_BUT_NOT_FINISHED_YET : ErrorTypes.UNEXPECTED_EXCEPTION.getErrorCode(), 0)); } } int taskId; for (ExperimentTaskResult result : results) { taskId = this.dao.createTask(result.getAnnotator(), result.getDataset(), result.getType().name(), result.getMatching().name(), EXPERIMENT_ID); if (result.state == ExperimentDAO.TASK_FINISHED) { this.dao.setExperimentTaskResult(taskId, result); } else { this.dao.setExperimentState(taskId, result.state); } } List<ExperimentTaskResult> retrievedResults = dao.getResultsOfExperiment(EXPERIMENT_ID); ExperimentTaskResult originalResult; for (ExperimentTaskResult retrievedResult : retrievedResults) { if (retrievedResult.state == ExperimentDAO.TASK_FINISHED) { Assert.assertTrue("Couldn't find " + retrievedResult.toString() + " inside of the expected results " + results.toString(), results.remove(retrievedResult)); } else { // We have to search them manually since the time stamps are // different originalResult = null; for (ExperimentTaskResult result : results) { if ((result.state == retrievedResult.state) && (result.annotator.equals(retrievedResult.annotator)) && (result.dataset.equals(retrievedResult.dataset)) && (result.errorCount == retrievedResult.errorCount) && (result.matching == retrievedResult.matching) && (result.type == retrievedResult.type)) { originalResult = result; break; } } Assert.assertNotNull("Couldn't find " + retrievedResult.toString() + " inside of the expected results " + results.toString(), originalResult); results.remove(originalResult); } } Assert.assertEquals("Not all expected results have been retrieved. Missing results " + results, 0, results.size()); }
From source file:org.jtransforms.utils.IOUtils.java
/** * Fills 2D matrix with random numbers.//ww w .ja v a2 s. co m * @param n1 rows * @param n2 columns * @param m 2D matrix */ public static void fillMatrix_2D(long n1, long n2, float[][] m) { Random r = new Random(2); for (int i = 0; i < n1; i++) { for (int j = 0; j < n2; j++) { m[i][j] = r.nextFloat(); } } }
From source file:com.intranet.intr.inbox.EmpControllerInbox.java
@RequestMapping(value = "/EajaxtestFoto", method = RequestMethod.GET) public @ResponseBody String getTimeFoto(Principal principal) { String name = principal.getName(); empleados po = new empleados(); try {//from w w w . ja va2 s . c om users u = usuarioService.getByLogin(name); po = empleadoService.ByNif(u.getNif()); } catch (Exception ex) { } String result = "/Intranet/resources/fotosPerfil/" + po.getNombrefotografia(); //System.out.println("ajaxtext"); Random rand = new Random(); float r = rand.nextFloat() * 100; //String result = "<br>Next Random # is <b>" + r + "</b>. Generated on <b>" + new Date().toString() + "</b>"; //System.out.println("Debug Message from CrunchifySpringAjaxJQuery Controller.." + new Date().toString()); return result; }
From source file:org.jtransforms.utils.IOUtils.java
/** * Fills 2D matrix with random numbers.//from w w w . ja v a 2 s.co m * @param n1 rows * @param n2 columns * @param m 2D matrix */ public static void fillMatrix_2D(long n1, long n2, float[] m) { Random r = new Random(2); for (int i = 0; i < n1; i++) { for (int j = 0; j < n2; j++) { m[(int) (i * n2 + j)] = r.nextFloat(); } } }
From source file:org.jtransforms.utils.IOUtils.java
/** * Fills 2D matrix with random numbers./* w w w. j av a 2 s . co m*/ * @param n1 rows * @param n2 columns * @param m 2D matrix */ public static void fillMatrix_2D(long n1, long n2, FloatLargeArray m) { Random r = new Random(2); for (long i = 0; i < n1; i++) { for (long j = 0; j < n2; j++) { m.setFloat(i * n2 + j, r.nextFloat()); } } }
From source file:com.linkedin.pinot.segments.v1.creator.OnHeapDictionariesTest.java
/** * Helper method to build a segment with random data as per the schema. * * @param segmentDirName Name of segment directory * @param segmentName Name of segment/* w ww.j a va2 s . c o m*/ * @param schema Schema for segment * @return Schema built for the segment * @throws Exception */ private Schema buildSegment(String segmentDirName, String segmentName, Schema schema) throws Exception { SegmentGeneratorConfig config = new SegmentGeneratorConfig(schema); config.setOutDir(segmentDirName); config.setFormat(FileFormat.AVRO); config.setSegmentName(segmentName); Random random = new Random(RANDOM_SEED); List<GenericRow> rows = new ArrayList<>(NUM_ROWS); for (int rowId = 0; rowId < NUM_ROWS; rowId++) { HashMap<String, Object> map = new HashMap<>(); map.put(INT_COLUMN, random.nextInt()); map.put(LONG_COLUMN, random.nextLong()); map.put(FLOAT_COLUMN, random.nextFloat()); map.put(DOUBLE_COLUMN, random.nextDouble()); map.put(STRING_COLUMN, RandomStringUtils.randomAscii(100)); GenericRow genericRow = new GenericRow(); genericRow.init(map); rows.add(genericRow); } SegmentIndexCreationDriverImpl driver = new SegmentIndexCreationDriverImpl(); driver.init(config, new GenericRowRecordReader(rows, schema)); driver.build(); LOGGER.info("Built segment {} at {}", segmentName, segmentDirName); return schema; }
From source file:com.intranet.intr.inbox.SupControllerInbox.java
@RequestMapping(value = "/ajaxtest2", method = RequestMethod.GET) public @ResponseBody String getTime(Principal principal) { String name = principal.getName(); int numMensa = numCorreosNOL(name); String result = "" + numMensa; //System.out.println("ajaxtext"); Random rand = new Random(); float r = rand.nextFloat() * 100; //String result = "<br>Next Random # is <b>" + r + "</b>. Generated on <b>" + new Date().toString() + "</b>"; //System.out.println("Debug Message from CrunchifySpringAjaxJQuery Controller.." + new Date().toString()); return result; }
From source file:org.shaman.terrain.vegetation.TreePlanter.java
private void plantTrees() { // Box testMesh = new Box(1, 1, 1); // Material testMat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); // testMat.setColor("Color", ColorRGBA.Red); //bucketing for speed improvement MultiMap<TreeInfo, TreeNode> nodes = new MultiValueMap<>(); //first, simple planting algorithm float density = 0.2f / size; Random rand = new Random(); Biome[] allBiomes = Biome.values();/*w w w . jav a 2 s . c om*/ for (int x = 0; x < biomes.getSize(); ++x) { for (int y = 0; y < biomes.getSize(); ++y) { if (map.getHeightAt(x, y) <= 0) { continue; } //check if we can plant here if (rand.nextFloat() > density) { continue; } //find highest scoring biome float[] v = biomes.getVectorAt(x, y); float max = 0; Biome biome = null; for (int i = 0; i < v.length; ++i) { if (v[i] > max) { max = v[i]; biome = allBiomes[i]; } } if (biome == null) { LOG.log(Level.WARNING, "no biome found at ({0},{1})", new Object[] { x, y }); continue; } //get tree sample Pair<Float, TreeInfo>[] trees = TREES.get(biome); float f = rand.nextFloat(); TreeInfo tree = null; for (int i = 0; i < trees.length; ++i) { if (trees[i].getLeft() > f) { tree = trees[i].getRight(); break; } } if (tree == null) { continue; } //create tree node TreeNode treeNode = new TreeNode(tree, app.getAssetManager(), app.getCamera()); treeNode.setUseHighRes(false); // Geometry treeNode = new Geometry("tree", testMesh); // treeNode.setMaterial(testMat); treeNode.setLocalScale(size); treeNode.rotate(-FastMath.HALF_PI, 0, 0); Vector3f pos = app.getHeightmapPoint(x + rand.nextFloat() - 0.5f, y + rand.nextFloat() - 0.5f); pos.x *= scaleFactor; pos.z *= scaleFactor; treeNode.setLocalTranslation(pos); nodes.put(tree, treeNode); } } for (Map.Entry<TreeInfo, Object> entries : nodes.entrySet()) { Collection<TreeNode> col = (Collection<TreeNode>) entries.getValue(); for (TreeNode n : col) { sceneNode.attachChild(n); } } LOG.info(sceneNode.getChildren().size() + " trees planted"); }