Example usage for java.security SecureRandom nextBoolean

List of usage examples for java.security SecureRandom nextBoolean

Introduction

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

Prototype

public boolean nextBoolean() 

Source Link

Document

Returns the next pseudorandom, uniformly distributed boolean value from this random number generator's sequence.

Usage

From source file:es.logongas.openshift.ant.JenkinsPasswordHashPropertyTask.java

/**
 * The MIT License//w ww  .ja  v  a2s . c  o  m
 * 
 * Copyright (c) 2004-2010, Sun Microsystems, Inc., Kohsuke Kawaguchi, David Calavera, Seiji Sogabe
 * Generates random salt.
 */
private String generateSalt() {
    StringBuilder buf = new StringBuilder();
    SecureRandom sr = new SecureRandom();
    for (int i = 0; i < 6; i++) {// log2(52^6)=34.20... so, this is about 32bit strong.
        boolean upper = sr.nextBoolean();
        char ch = (char) (sr.nextInt(26) + 'a');
        if (upper) {
            ch = Character.toUpperCase(ch);
        }
        buf.append(ch);
    }
    return buf.toString();
}

From source file:de.hybris.platform.cuppytrail.impl.DefaultSecureTokenService.java

private int[] computePaddingLengths(final SecureRandom random) {
    final int firstNumber = random.nextInt(8);// rand 0 through 7
    final int windowAdjustment = 7 - firstNumber;
    final int secondNumber = windowAdjustment + random.nextInt(8 - windowAdjustment);

    if (random.nextBoolean()) {
        return new int[] { firstNumber, secondNumber };
    }//from   w  w  w.ja va 2s . c  o m
    return new int[] { secondNumber, firstNumber };
}