Java Code Examples for java.security.SecureRandom#nextFloat()

The following examples show how to use java.security.SecureRandom#nextFloat() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SecureRandom.java    From CompetitiveJava with MIT License 6 votes vote down vote up
public static void generateSecureRandomValues() {
    SecureRandom secureRandom = new SecureRandom();

    int randomInt = secureRandom.nextInt();
    long randomLong = secureRandom.nextLong();
    float randomFloat = secureRandom.nextFloat();
    double randomDouble = secureRandom.nextDouble();
    boolean randomBoolean = secureRandom.nextBoolean();

    IntStream randomIntStream = secureRandom.ints();
    LongStream randomLongStream = secureRandom.longs();
    DoubleStream randomDoubleStream = secureRandom.doubles();

    byte[] values = new byte[124];
    secureRandom.nextBytes(values);
}
 
Example 2
Source File: Sorting.java    From streamsupport with GNU General Public License v2.0 6 votes vote down vote up
void build(float[] x, int a, int g, int z, int n, int p, SecureRandom random) {
    int fromIndex = 0;
    float negativeValue = -random.nextFloat();
    float positiveValue =  random.nextFloat();

    writeValue(x, negativeValue, fromIndex, n);
    fromIndex += n;

    writeValue(x, -0.0f, fromIndex, g);
    fromIndex += g;

    writeValue(x, 0.0f, fromIndex, z);
    fromIndex += z;

    writeValue(x, positiveValue, fromIndex, p);
    fromIndex += p;

    writeValue(x, Float.NaN, fromIndex, a);
}
 
Example 3
Source File: Sorting.java    From streamsupport with GNU General Public License v2.0 6 votes vote down vote up
void build(double[] x, int a, int g, int z, int n, int p, SecureRandom random) {
    int fromIndex = 0;
    double negativeValue = -random.nextFloat();
    double positiveValue =  random.nextFloat();

    writeValue(x, negativeValue, fromIndex, n);
    fromIndex += n;

    writeValue(x, -0.0d, fromIndex, g);
    fromIndex += g;

    writeValue(x, 0.0d, fromIndex, z);
    fromIndex += z;

    writeValue(x, positiveValue, fromIndex, p);
    fromIndex += p;

    writeValue(x, Double.NaN, fromIndex, a);
}
 
Example 4
Source File: SecureRandomDemo.java    From tutorials with MIT License 6 votes vote down vote up
public static void generateSecureRandomValues() {
    SecureRandom sr = new SecureRandom();

    int randomInt = sr.nextInt();
    long randomLong = sr.nextLong();
    float randomFloat = sr.nextFloat();
    double randomDouble = sr.nextDouble();
    boolean randomBoolean = sr.nextBoolean();

    IntStream randomIntStream = sr.ints();
    LongStream randomLongStream = sr.longs();
    DoubleStream randomDoubleStream = sr.doubles();

    byte[] values = new byte[124];
    sr.nextBytes(values);
}
 
Example 5
Source File: SecureRandomDemo.java    From tutorials with MIT License 6 votes vote down vote up
public static void generateSecureRandomValues() {
    SecureRandom sr = new SecureRandom();

    int randomInt = sr.nextInt();
    long randomLong = sr.nextLong();
    float randomFloat = sr.nextFloat();
    double randomDouble = sr.nextDouble();
    boolean randomBoolean = sr.nextBoolean();

    IntStream randomIntStream = sr.ints();
    LongStream randomLongStream = sr.longs();
    DoubleStream randomDoubleStream = sr.doubles();

    byte[] values = new byte[124];
    sr.nextBytes(values);
}
 
Example 6
Source File: TestHadoop2ClusterManagerUtil.java    From rubix with Apache License 2.0 5 votes vote down vote up
static String getSaltString()
{
  String saltchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
  StringBuilder salt = new StringBuilder();
  SecureRandom rnd = new SecureRandom();
  while (salt.length() < 18) { // length of the random string.
    int index = (int) (rnd.nextFloat() * saltchars.length());
    salt.append(saltchars.charAt(index));
  }
  String saltStr = salt.toString();
  return saltStr;
}
 
Example 7
Source File: TaskExecutionDemo.java    From helix with Apache License 2.0 5 votes vote down vote up
private static void populateDummyData(TaskResultStore taskResultStore) throws Exception {
  float fraudProbability = 0.01f;
  float clickProbability = 0.01f;
  int numImps = NUM_IMP_EVENTS;
  SecureRandom rand = new SecureRandom();
  String[] countries = {
      "US", "CANADA", "UK", "CHINA", "UNKNOWN"
  };
  String[] genders = {
      "M", "F", "UNKNOWN"
  };
  for (int i = 0; i < numImps; i++) {
    boolean isFraudulent = (rand.nextFloat() <= fraudProbability);
    String impEventId = "" + Math.abs(rand.nextLong());
    String impEvent = impEventId; // event id
    impEvent += "," + isFraudulent;
    impEvent += "," + countries[rand.nextInt(countries.length)];
    impEvent += "," + genders[rand.nextInt(genders.length)];
    taskResultStore.rpush(FilterTask.IMPRESSIONS, impEvent);

    boolean isClick = (rand.nextFloat() <= clickProbability);
    if (isClick) {
      String clickEvent = "" + Math.abs(rand.nextLong()); // event id
      isFraudulent = (rand.nextFloat() <= fraudProbability);
      clickEvent += "," + isFraudulent;
      clickEvent += "," + impEventId;
      taskResultStore.rpush(FilterTask.CLICKS, clickEvent);
    }
  }
  System.out.println("Done populating dummy data");
}