List of usage examples for java.util Random nextFloat
public float nextFloat()
From source file:url.Domain.java
public String getColor() { Random random = new Random(); final float hue = random.nextFloat() + 0.5f; final float saturation = 0.9f;//1.0 for brilliant, 0.0 for dull final float luminance = 1.0f; //1.0 for brighter, 0.0 for black*/ Color color = Color.getHSBColor(hue, saturation, luminance); Formatter f = new Formatter(new StringBuffer("#")); f.format("%06x", color.getRGB()); f.toString();/*from w w w. ja v a 2 s .c om*/ return f.toString(); }
From source file:at.salzburgresearch.kmt.zkconfig.ZookeeperConfigurationTest.java
@Test public void testFloat() throws Exception { Configuration config = new ZookeeperConfiguration(zkConnection, 5000, "/test"); final String key = UUID.randomUUID().toString(); final Random random = new Random(); final float val1 = random.nextFloat(); final Float val2 = random.nextFloat(); assertThat(config.getProperty(key), nullValue()); config.setProperty(key, val1); assertEquals(val1, config.getFloat(key), 10e-6); assertEquals(new Float(val1), config.getFloat(key, val2)); config.setProperty(key, val2); assertEquals(val2, config.getFloat(key), 10e-6); assertEquals(val2, config.getFloat(key, Float.valueOf(val1))); }
From source file:ImageBouncer.java
public ImageBouncer(Image image) { previousTimes = new long[128]; previousTimes[0] = System.currentTimeMillis(); previousIndex = 1;//from w w w . j a v a 2s .c o m previousFilled = false; mOriginalImage = image; setImageType("TYPE_INT_RGB"); Random random = new Random(); mX = random.nextFloat() * 500; mY = random.nextFloat() * 500; mWidth = image.getWidth(this); mHeight = image.getHeight(this); mDeltaX = random.nextFloat() * 3; mDeltaY = random.nextFloat() * 3; // Make sure points are within range. addComponentListener(new ComponentAdapter() { public void componentResized(ComponentEvent ce) { Dimension d = getSize(); if (mX < 0) mX = 0; else if (mX + mWidth >= d.width) mX = d.width - mWidth - 1; if (mY < 0) mY = 0; else if (mY + mHeight >= d.height) mY = d.height - mHeight - 1; } }); }
From source file:com.linkedin.pinot.index.writer.FixedByteWidthRowColDataFileWriterTest.java
@Test public void testSingleColFloat() throws Exception { File wfile = new File("test_single_col_writer.dat"); wfile.delete();/*from w w w .ja v a2s . c o m*/ final int rows = 100; final int cols = 1; final int[] columnSizes = new int[] { 4 }; FixedByteSingleValueMultiColWriter writer = new FixedByteSingleValueMultiColWriter(wfile, rows, cols, columnSizes); final float[] data = new float[rows]; Random r = new Random(); for (int i = 0; i < rows; i++) { data[i] = r.nextFloat(); writer.setFloat(i, 0, data[i]); } writer.close(); File rfile = new File("test_single_col_writer.dat"); PinotDataBuffer buffer = PinotDataBuffer.fromFile(rfile, ReadMode.mmap, FileChannel.MapMode.READ_WRITE, "testing"); FixedByteSingleValueMultiColReader reader = new FixedByteSingleValueMultiColReader(buffer, rows, cols, columnSizes); for (int i = 0; i < rows; i++) { Assert.assertEquals(reader.getFloat(i, 0), data[i]); } reader.close(); rfile.delete(); }
From source file:cytoscape.render.immed.GraphGraphicsTest.java
private long drawCurrentFull(Random rand) { final float nodeSizeFactor = 50f; float size = (float) canvasSize; long begin = System.nanoTime(); for (int i = 0; i < numNodes; i++) { float x = rand.nextFloat() * (rand.nextBoolean() ? size : -size); float y = rand.nextFloat() * (rand.nextBoolean() ? size : -size); currentGraphGraphics.drawNodeFull((byte) (i % (int) GraphGraphics.s_last_shape), x, y, (x + (rand.nextFloat() * nodeSizeFactor)), (y + (rand.nextFloat() * nodeSizeFactor)), Color.blue, 1.0f + (i % 10), Color.yellow); }// ww w . j a v a2s .c o m long end = System.nanoTime(); long nodeDur = end - begin; BasicStroke edgeStroke = new BasicStroke(1f); begin = System.nanoTime(); for (int i = 0; i < numEdges; i++) { currentGraphGraphics.drawEdgeFull((byte) ((i % 7) - 8), rand.nextFloat() * (20f), Color.red, (byte) ((i % 7) - 8), rand.nextFloat() * (20f), Color.orange, rand.nextFloat() * (rand.nextBoolean() ? size : -size), rand.nextFloat() * (rand.nextBoolean() ? size : -size), currentGraphGraphics.m_noAnchors, rand.nextFloat() * (rand.nextBoolean() ? size : -size), rand.nextFloat() * (rand.nextBoolean() ? size : -size), 1f, edgeStroke, Color.green); } end = System.nanoTime(); long duration = (end - begin) + nodeDur; // try { // ImageIO.write(image,"PNG",new File("/tmp/homer-current-" + rand.nextInt(100) + ".png")); // } catch (IOException ioe) { ioe.printStackTrace(); } return duration; }
From source file:cytoscape.render.immed.GraphGraphicsTest.java
private long drawOldFull(Random rand) { final float nodeSizeFactor = 50f; float size = (float) canvasSize; long begin = System.nanoTime(); for (int i = 0; i < numNodes; i++) { float x = rand.nextFloat() * (rand.nextBoolean() ? size : -size); float y = rand.nextFloat() * (rand.nextBoolean() ? size : -size); oldGraphGraphics.drawNodeFull((byte) (i % (int) OldGraphGraphics.s_last_shape), x, y, (x + (rand.nextFloat() * nodeSizeFactor)), (y + (rand.nextFloat() * nodeSizeFactor)), Color.blue, 1.0f + (i % 10), Color.yellow); }/* w w w . j av a 2 s. co m*/ long end = System.nanoTime(); long nodeDur = end - begin; BasicStroke edgeStroke = new BasicStroke(1f); begin = System.nanoTime(); for (int i = 0; i < numEdges; i++) { oldGraphGraphics.drawEdgeFull((byte) ((i % 7) - 8), rand.nextFloat() * (20f), Color.red, (byte) ((i % 7) - 8), rand.nextFloat() * (20f), Color.orange, rand.nextFloat() * (rand.nextBoolean() ? size : -size), rand.nextFloat() * (rand.nextBoolean() ? size : -size), oldGraphGraphics.m_noAnchors, rand.nextFloat() * (rand.nextBoolean() ? size : -size), rand.nextFloat() * (rand.nextBoolean() ? size : -size), 1f, Color.green, 0f); } end = System.nanoTime(); long duration = (end - begin) + nodeDur; // try { // ImageIO.write(image,"PNG",new File("/tmp/homer-old-" + rand.nextInt(100) + ".png")); // } catch (IOException ioe) { ioe.printStackTrace(); } return duration; }
From source file:org.cytoscape.graph.render.immed.GraphGraphicsTest.java
private long drawOldFull(Random rand) { final float nodeSizeFactor = 50f; float size = (float) canvasSize; long begin = System.nanoTime(); for (int i = 0; i < numNodes; i++) { float x = rand.nextFloat() * (rand.nextBoolean() ? size : -size); float y = rand.nextFloat() * (rand.nextBoolean() ? size : -size); oldGraphGraphics.drawNodeFull((byte) (i % (int) OldGraphGraphics.s_last_shape), x, y, (x + (rand.nextFloat() * nodeSizeFactor)), (y + (rand.nextFloat() * nodeSizeFactor)), Color.blue, 1.0f + (i % 10), Color.yellow); }/*from w w w . j a v a2 s . co m*/ long end = System.nanoTime(); long nodeDur = end - begin; BasicStroke edgeStroke = new BasicStroke(1f); begin = System.nanoTime(); for (int i = 0; i < numEdges; i++) { oldGraphGraphics.drawEdgeFull((byte) ((i % 7) - 8), rand.nextFloat() * (20f), Color.red, (byte) ((i % 7) - 8), rand.nextFloat() * (20f), Color.orange, rand.nextFloat() * (rand.nextBoolean() ? size : -size), rand.nextFloat() * (rand.nextBoolean() ? size : -size), oldGraphGraphics.m_noAnchors, rand.nextFloat() * (rand.nextBoolean() ? size : -size), rand.nextFloat() * (rand.nextBoolean() ? size : -size), 1f, Color.green, 0f); } end = System.nanoTime(); long duration = (end - begin) + nodeDur; return duration; }
From source file:org.cytoscape.graph.render.immed.GraphGraphicsTest.java
private long drawCurrentFull(Random rand) { final float nodeSizeFactor = 50f; float size = (float) canvasSize; long begin = System.nanoTime(); for (int i = 0; i < numNodes; i++) { float x = rand.nextFloat() * (rand.nextBoolean() ? size : -size); float y = rand.nextFloat() * (rand.nextBoolean() ? size : -size); currentGraphGraphics.drawNodeFull((byte) (i % (int) GraphGraphics.s_last_shape), x, y, (x + (rand.nextFloat() * nodeSizeFactor)), (y + (rand.nextFloat() * nodeSizeFactor)), Color.blue, 1.0f + (i % 10), null, Color.yellow); }/*from w w w . ja v a 2s . co m*/ long end = System.nanoTime(); long nodeDur = end - begin; BasicStroke edgeStroke = new BasicStroke(1f); begin = System.nanoTime(); for (int i = 0; i < numEdges; i++) { currentGraphGraphics.drawEdgeFull((byte) ((i % 7) - 8), rand.nextFloat() * (20f), Color.red, (byte) ((i % 7) - 8), rand.nextFloat() * (20f), Color.orange, rand.nextFloat() * (rand.nextBoolean() ? size : -size), rand.nextFloat() * (rand.nextBoolean() ? size : -size), currentGraphGraphics.m_noAnchors, rand.nextFloat() * (rand.nextBoolean() ? size : -size), rand.nextFloat() * (rand.nextBoolean() ? size : -size), 1f, edgeStroke, Color.green); } end = System.nanoTime(); long duration = (end - begin) + nodeDur; // try { // ImageIO.write(image,"PNG",new File("/tmp/homer-current-" + rand.nextInt(100) + ".png")); // } catch (IOException ioe) { ioe.printStackTrace(); } return duration; }
From source file:Bouncer.java
public Bouncer() { previousTimes = new long[128]; previousTimes[0] = System.currentTimeMillis(); previousIndex = 1;/*from www .j av a 2 s. c o m*/ previousFilled = false; mN = 38; mPoints = new float[mN]; mDeltas = new float[mN]; Random random = new Random(); for (int i = 0; i < mN; i++) { mPoints[i] = random.nextFloat() * 500; mDeltas[i] = random.nextFloat() * 3; } addComponentListener(new ComponentAdapter() { public void componentResized(ComponentEvent ce) { Dimension d = getSize(); for (int i = 0; i < mN; i++) { int limit = ((i % 2) == 0) ? d.width : d.height; if (mPoints[i] < 0) mPoints[i] = 0; else if (mPoints[i] >= limit) mPoints[i] = limit - 1; } } }); }
From source file:TextBouncer.java
public TextBouncer(String s, Font f) { previousTimes = new long[128]; previousTimes[0] = System.currentTimeMillis(); previousIndex = 1;/* w ww. j ava 2 s.c o m*/ previousFilled = false; mString = s; setFont(f); Random random = new Random(); mX = random.nextFloat() * 500; mY = random.nextFloat() * 500; mDeltaX = random.nextFloat() * 3; mDeltaY = random.nextFloat() * 3; mShearX = random.nextFloat() / 2; mShearY = random.nextFloat() / 2; mShearDeltaX = mShearDeltaY = .05f; FontRenderContext frc = new FontRenderContext(null, true, false); Rectangle2D bounds = getFont().getStringBounds(mString, frc); mWidth = (float) bounds.getWidth(); mHeight = (float) bounds.getHeight(); // Make sure points are within range. addComponentListener(new ComponentAdapter() { public void componentResized(ComponentEvent ce) { Dimension d = getSize(); if (mX < 0) mX = 0; else if (mX + mWidth >= d.width) mX = d.width - mWidth - 1; if (mY < 0) mY = 0; else if (mY + mHeight >= d.height) mY = d.height - mHeight - 1; } }); }