Package java.security

Examples of java.security.SecureRandom.nextDouble()


  public static String createRandomString(int length){
    if(length<1) return "";
    SecureRandom sr = new SecureRandom();
    StringBuilder sb=new StringBuilder();
    for(int i=0;i<length;i++){
      int rnd=(int) (sr.nextDouble()*(CHARS.length-1));
      sb.append(CHARS[rnd]);
    }
    return sb.toString();
  }
 
View Full Code Here


  public static String createRandomStringLC(int length){
    if(length<1) return "";
    SecureRandom sr = new SecureRandom();
    StringBuilder sb=new StringBuilder();
    for(int i=0;i<length;i++){
      int rnd=(int) (sr.nextDouble()*(CHARS_LC.length-1));
      sb.append(CHARS_LC[rnd]);
    }
    return sb.toString();
  }
}
View Full Code Here

          throw new RuntimeException(e);
        }

        for (int i = 0; i < iterations; i++)
        {
          String key = "abc" + (rnd.nextDouble() * iterations);
          keys.add(key);
          map.put(key, new BufferedWebResponse(null));

          int randomMax = keys.size() - 1;
          int toRemove = randomMax == 0 ? 0 : rnd.nextInt(randomMax);
View Full Code Here

        if (lower >= upper) {
            throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
                                                lower, upper, false);
        }
        SecureRandom sec = getSecRan();
        final double r = sec.nextDouble();
        final double scaled = r * upper + (1.0 - r) * lower + r;
        return (int)FastMath.floor(scaled);
    }

    /** {@inheritDoc} */
 
View Full Code Here

        if (lower >= upper) {
            throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
                                                lower, upper, false);
        }
        SecureRandom sec = getSecRan();
        final double r = sec.nextDouble();
        final double scaled = r * upper + (1.0 - r) * lower + r;
        return (long)FastMath.floor(scaled);
    }

    /**
 
View Full Code Here

          throw new RuntimeException(e);
        }

        for (int i = 0; i < iterations; i++)
        {
          String key = "abc" + (rnd.nextDouble() * iterations);
          keys.add(key);
          map.put(key, new BufferedWebResponse(null));

          int randomMax = keys.size() - 1;
          int toRemove = randomMax == 0 ? 0 : rnd.nextInt(randomMax);
View Full Code Here

          throw new RuntimeException(e);
        }

        for (int i = 0; i < iterations; i++)
        {
          String key = "abc" + (rnd.nextDouble() * iterations);
          keys.add(key);
          map.put(key, new BufferedWebResponse(null));

          int randomMax = keys.size() - 1;
          int toRemove = randomMax == 0 ? 0 : rnd.nextInt(randomMax);
View Full Code Here

          if (lower >= upper) {
              throw new IllegalArgumentException
                ("lower bound must be < upper bound");
          }
          SecureRandom sec = getSecRan();
          return lower + (int) (sec.nextDouble() * (upper - lower + 1));
    }

    /**
     * Generate a random long value uniformly distributed between
     * <code>lower</code> and <code>upper</code>, inclusive.  This algorithm
View Full Code Here

        if (lower >= upper) {
            throw new IllegalArgumentException
            ("lower bound must be < upper bound");
        }
        SecureRandom sec = getSecRan();
        return lower + (long) (sec.nextDouble() * (upper - lower + 1));
    }

    /**
     * {@inheritDoc}
     * <p>
 
View Full Code Here

          throw new RuntimeException(e);
        }

        for (int i = 0; i < iterations; i++)
        {
          String key = "abc" + (rnd.nextDouble() * iterations);
          keys.add(key);
          map.put(key, new BufferedWebResponse(null));

          int randomMax = keys.size() - 1;
          int toRemove = randomMax == 0 ? 0 : rnd.nextInt(randomMax);
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.