Get a SecureRandom instance. This method should me used by JDK
internal code in favor of calling "new SecureRandom()". That needs to
iterate through the provider table to find the default SecureRandom
implementation, which is fairly inefficient.
559060
public static SecureRandom getSecureRandom() {
        // we use double checked locking to minimize synchronization
        // works because we use a volatile reference
        SecureRandom r = secureRandom;
        if (r == null) {
            synchronized (LOCK) {
                r = secureRandom;
                if (r == null) {
                    r = new SecureRandom();
                    secureRandom = r;
                }
            }
        }
        return r;
    }
126338
@SuppressWarnings("unchecked")
    public static <T> Randomizer<T> asRandomizer(final Supplier<T> supplier) {

        class RandomizerProxy implements InvocationHandler {

            private final Supplier<?> target;

            private RandomizerProxy(final Supplier<?> target) {
                this.target = target;
            }

            @Override
            public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
                if ("getRandomValue".equals(method.getName())) {
                    Method getMethod = target.getClass().getMethod("get");
                    getMethod.setAccessible(true);
                    return getMethod.invoke(target);
                }
                return null;
            }
        }

        return (Randomizer<T>) Proxy.newProxyInstance(
                Randomizer.class.getClassLoader(),
                new Class[]{Randomizer.class},
                new RandomizerProxy(supplier));
    }
32878
public int getRandomInt() {
    	
        Integer newInt = null;
        do {
        	newInt = randomGenerator.nextInt();
        } while(this.previousRandomInts.contains(newInt));
        this.previousRandomInts.add(newInt);
        return newInt.intValue();
    }
1250953
def generate_key(key_length=64):
    
    if hasattr(random, 'SystemRandom'):
        logging.info('Generating a secure random key using SystemRandom.')
        choice = random.SystemRandom().choice
    else:
        msg = "WARNING: SystemRandom not present. Generating a random "\
              "key using random.choice (NOT CRYPTOGRAPHICALLY SECURE)."
        logging.warning(msg)
        choice = random.choice
    return ''.join(map(lambda x: choice(string.digits + string.ascii_letters),
                   range(key_length)))
944237
private function getDefaultGenerator()
    {
        foreach (self::$defaultGenerators as $generator) {
            /** @var Generator\Generator $generator */
            $generator = new $generator();

            if ($generator->isSupported()) {
                return $generator;
            }
        }

        throw new GeneratorException('Default secure random byte generators are not supported by the system');
    }
193835
public static Date newRandomDate(final Date from)
	{
		final Random secrand = new SecureRandom();
		final double randDouble = -secrand.nextDouble() * from.getTime();
		final double randomDouble = from.getTime() - secrand.nextDouble();
		final double result = randDouble * randomDouble;
		return new Date((long)result);
	}
402646
public KeyPair getRandomKeyPair(int keySize){  
        KeyPairGenerator pairgen;
		try {
			pairgen = KeyPairGenerator.getInstance(algorithm);
			SecureRandom random = new SecureRandom();  
	        pairgen.initialize(keySize, random);  
	        return pairgen.generateKeyPair();
		} catch (Exception e) {
			log.error(e.getMessage(),e);
		}  
        return null;  
    }
902775
@Override
    public E getRandomValue() {
        int randomIndex = random.nextInt(enumConstants.size());
        return enumConstants.get(randomIndex);
    }
8295
public static SecretKey newSecretKey() {

        // FYI: AES keys are just random bytes from a strong source of randomness.

        // Get a key generator instance
        KeyGenerator keyGenerator;
        try {
            keyGenerator = KeyGenerator.getInstance(SYMMETRIC_ALGORITHM);
        } catch (NoSuchAlgorithmException e) {
            try {
                if (SecurityProvider.addProvider()) {
                    keyGenerator = KeyGenerator.getInstance(SYMMETRIC_ALGORITHM);
                } else keyGenerator = null;
            } catch (NoSuchAlgorithmException e1) {
                keyGenerator = null;
            }
            if (keyGenerator == null) {
                throw new IllegalStateException("Algorithm unavailable: " + SYMMETRIC_ALGORITHM, e);
            }
        }

        // Generate a key:
        keyGenerator.init(SYMMETRIC_KEY_SIZE);
        return keyGenerator.generateKey();
    }
892256
public SecretKey generateSecretKey() throws NoSuchAlgorithmException {
        final KeyGenerator keyGen = KeyGenerator.getInstance("AES");
        final SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
        keyGen.init(256, random);
        return this.secretKey = keyGen.generateKey();
    }
1291410
public static RAND getRand() {
        // construct a secure seed
        int seedLength = IdemixUtils.FIELD_BYTES;
        SecureRandom random = new SecureRandom();
        byte[] seed = random.generateSeed(seedLength);

        // create a new amcl.RAND and initialize it with the generated seed
        RAND rng = new RAND();
        rng.clean();
        rng.seed(seedLength, seed);

        return rng;
    }
1141417
public static String generateSecureRandomId() {
        val generator = getNativeInstance();
        val charMappings = new char[]{
            'a', 'b', 'c', 'd', 'e', 'f', 'g',
            'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
            'p'};

        val bytes = new byte[SECURE_ID_BYTES_LENGTH];
        generator.nextBytes(bytes);

        val chars = new char[SECURE_ID_CHARS_LENGTH];
        IntStream.range(0, bytes.length).forEach(i -> {
            val left = bytes[i] >> SECURE_ID_SHIFT_LENGTH & HEX_HIGH_BITS_BITWISE_FLAG;
            val right = bytes[i] & HEX_HIGH_BITS_BITWISE_FLAG;
            chars[i * 2] = charMappings[left];
            chars[i * 2 + 1] = charMappings[right];
        });
        return String.valueOf(chars);
    }
1049745
public static Random get() {
        Random random = THREAD_LOCAL_RANDOM.get();
        if (random == null) {
            long seed = SEED_GENERATOR.nextLong();
            random = new Random(seed);
            THREAD_LOCAL_RANDOM.set(random);
        }
        return random;
    }
809361
private static String createSecureRandom() {
        try {
            final String no = "" + SECURE_RANDOM.nextInt();
            final MessageDigest md = MessageDigest.getInstance("SHA-1");
            final byte[] digest = md.digest(no.getBytes());
            return encodeBase64(digest);
        } catch (final NoSuchAlgorithmException ex) {
            throw new RuntimeException(ex);
        }
    }
100100
private Function<Object, String> createDecryptor() throws GeneralSecurityException {
		Cipher cipher = Cipher.getInstance(transformationType);
		if (useIV) {
			cipher.init(Cipher.DECRYPT_MODE, secretKey,
					encryptCipher.getParameters().getParameterSpec(IvParameterSpec.class));
		} else {
			cipher.init(Cipher.DECRYPT_MODE, secretKey);
		}

		return secret -> {
			if (secret == null) {
				return null;
			}

			String secretStr = secret.toString();
			if (!secretStr.isEmpty()) {
				synchronized (cipher) {
					try {
						return decrypt(cipher, secretKey, secretStr);
					} catch (Exception ex) {
						return secretStr;
					}
				}
			} else {
				return secretStr;
			}
		};
	}
1247027
@Override
    protected InjectionPoint getInjectionPoint(InvokeInstruction invoke, ConstantPoolGen cpg,
                                               InstructionHandle handle) {
        assert invoke != null && cpg != null;

        //ByteCode.printOpCode(invoke,cpg);

        if(CIPHER_GET_INSTANCE.matches(invoke,cpg)) {
            return new InjectionPoint(new int[]{0}, getBugPattern());
        }
        else if(CIPHER_GET_INSTANCE_PROVIDER.matches(invoke,cpg)) {
            return new InjectionPoint(new int[]{1}, getBugPattern());
        }
        else if(KEYGENERATOR_GET_INSTANCE.matches(invoke,cpg)) {
            return new InjectionPoint(new int[]{0}, getBugPattern());
        }
        else if(KEYGENERATOR_GET_INSTANCE_PROVIDER.matches(invoke,cpg)) {
            return new InjectionPoint(new int[]{1}, getBugPattern());
        }
        return InjectionPoint.NONE;
    }
706643
protected synchronized Random getRandom() {
        if (this.random == null) {
            try {
                Class clazz = Class.forName(randomClass);
                this.random = (Random) clazz.newInstance();
                long seed = System.currentTimeMillis();
                char[] entropy = getEntropy().toCharArray();
                for (int i = 0; i < entropy.length; i++) {
                    long update = ((byte) entropy[i]) << ((i % 8) * 8);
                    seed ^= update;
                }
                this.random.setSeed(seed);
            } catch (Exception e) {
                this.random = new java.util.Random();
            }
        }
        return (this.random);
    }