Example usage for java.security SecureRandom nextFloat

List of usage examples for java.security SecureRandom nextFloat

Introduction

In this page you can find the example usage for java.security SecureRandom nextFloat.

Prototype

public float nextFloat() 

Source Link

Document

Returns the next pseudorandom, uniformly distributed float value between 0.0 and 1.0 from this random number generator's sequence.

Usage

From source file:edu.stanford.mobisocial.dungbeetle.model.Feed.java

public static int colorFor(String name) {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try {//from   w ww.java2s.c  o m
        bos.write(name.getBytes());
    } catch (IOException e) {
    }
    SecureRandom r = new SecureRandom(bos.toByteArray());
    float hsv[] = new float[] { baseHues[r.nextInt(baseHues.length)], r.nextFloat(), r.nextFloat() };
    hsv[0] = hsv[0] + 20 * r.nextFloat() - 10;
    hsv[1] = hsv[1] * 0.2f + 0.8f;
    hsv[2] = hsv[2] * 0.2f + 0.8f;
    return Color.HSVToColor(hsv);
}

From source file:edu.stanford.mobisocial.dungbeetle.model.DbObject.java

private static int colorFor(Long hash) {
    float[] baseHues = Feed.getBaseHues();
    ByteBuffer bos = ByteBuffer.allocate(8);
    bos.putLong(hash);//from  ww  w.  j  av a2s.  c o m
    byte[] hashBytes = new byte[8];
    bos.position(0);
    bos.get(hashBytes);
    SecureRandom r = new SecureRandom(hashBytes);
    float hsv[] = new float[] { baseHues[r.nextInt(baseHues.length)], r.nextFloat(), r.nextFloat() };
    hsv[0] = hsv[0] + 20 * r.nextFloat() - 10;
    hsv[1] = hsv[1] * 0.2f + 0.8f;
    hsv[2] = hsv[2] * 0.2f + 0.8f;
    return Color.HSVToColor(hsv);
}