1 package org
.asamk
.signal
.util
;
3 import java
.security
.NoSuchAlgorithmException
;
4 import java
.security
.SecureRandom
;
6 public class RandomUtils
{
8 private static final ThreadLocal
<SecureRandom
> LOCAL_RANDOM
= new ThreadLocal
<SecureRandom
>() {
10 protected SecureRandom
initialValue() {
11 SecureRandom rand
= getSecureRandomUnseeded();
13 // Let the SecureRandom seed it self initially
20 private static SecureRandom
getSecureRandomUnseeded() {
22 return SecureRandom
.getInstance("NativePRNG");
23 } catch (NoSuchAlgorithmException e
) {
24 // Fallback to SHA1PRNG if NativePRNG is not available (e.g. on windows)
26 return SecureRandom
.getInstance("SHA1PRNG");
27 } catch (NoSuchAlgorithmException e1
) {
28 // Fallback to default
29 return new SecureRandom();
34 public static SecureRandom
getSecureRandom() {
35 return LOCAL_RANDOM
.get();