Create a new random number generator instance we should use for generating session identifiers.
481832
private SecureRandom createSecureRandom() {
        SecureRandom result;
        try {
            result = SecureRandom.getInstance("SHA1PRNG");
        } catch (NoSuchAlgorithmException e) {
            result = new SecureRandom();
        }

        // Force seeding to take place.
        result.nextInt();
        return result;
    }
1319648
def new_credentials():
    
    identifier = binascii.b2a_hex(os.urandom(8)).decode().upper()
    seed = binascii.b2a_hex(os.urandom(32))  # Corresponds to private key
    return identifier, seed
25832
def generate(cls):
        
        return cls(libnacl.randombytes(PrivateKey.SIZE), encoder=encoding.RawEncoder)
943467
public void init() {
        if(random == null) {
            throw new IllegalArgumentException("init should be called after random number generator set");
        }
		readNames();
        usernameGenerator = initSpewGenerator("username");
        emailGenerator = initSpewGenerator("email");
        initialized = true;
	}
1374276
def create_session(username, password):
    
    user = User.objects.get_user_by_password(username, password)
    auth_session_engine = get_config('auth_session_engine')
    if not user:
        raise InvalidInput('Username or password incorrect')
    session_key = random_string(15)
    while auth_session_engine.get(session_key):
        session_key = random_string(15)
    auth_session_engine.set(session_key, user.username, get_config('auth_session_expire'))
    return {'session_key': session_key, 'user': user}
407976
def generate_id(cls, prefix="pelix-"):
        
        if not prefix:
            # Normalize string
            prefix = ""
        else:
            # Truncate long prefixes
            prefix = prefix[:8]

        # Prepare the missing part
        nb_bytes = (23 - len(prefix)) // 2

        random_bytes = os.urandom(nb_bytes)
        if sys.version_info[0] >= 3:
            random_ints = [char for char in random_bytes]
        else:
            random_ints = [ord(char) for char in random_bytes]

        random_id = "".join("{0:02x}".format(value) for value in random_ints)
        return "{0}{1}".format(prefix, random_id)
735214
def id_generator(size=15, random_state=None):
    """"""
    chars = list(string.ascii_uppercase + string.digits)
    return ''.join(random_state.choice(chars, size, replace=True))
473204
def gen_random_key(size=32):
    
    import os
    if hasattr(os, "urandom"): # Python 2.4+
        return os.urandom(size)

    # Try using PyCrypto if available
    try:
        from Crypto.Util.randpool import RandomPool
        from Crypto.Hash import SHA256
        return RandomPool(hash=SHA256).get_bytes(size)

    except ImportError:
        print >>sys.stderr, "WARNING: The generated key will not be cryptographically-secure key. Consider using Python 2.4+ to generate the key, or install PyCrypto."

        # Stupid random generation
        import random
        L = []
        for i in range(size):
            L.append(chr(random.randint(0, 255)))
        return "".join(L)
716027
def generate_session_id(self):
        """"""
        secret_key = self._config.secret_key
        while True:
            rand = os.urandom(16)
            now = time.time()
            session_id = sha1(utf8("%s%s%s%s" % (
                rand, now, self.handler.request.remote_ip, secret_key)))
            session_id = session_id.hexdigest()
            if session_id not in self.store:
                break

        return session_id
404905
def generate_random_type(valid):
    
    type = choice(['int', 'str'])

    r = lambda: randrange(-1000000000, 1000000000)

    if type == 'int':
        return int,  (r() if valid else str(r()) for i in itertools.count())
    elif type == 'str':
        return str, (str(r()) if valid else r() for i in itertools.count())
    else:
        raise AssertionError('!')
286190
public Serializable generate(SessionImplementor session, Object object)
            throws HibernateException {
        UUID uuid = UUID.randomUUID();
        StringBuilder sb = new StringBuilder();

        sb.append(Long.toHexString(uuid.getMostSignificantBits()));
        sb.append(Long.toHexString(uuid.getLeastSignificantBits()));

        while (sb.length() < 32) {
            sb.append('0');
        }

        return sb.toString();
    }
1097735
function generate() {
      store.generate(req);
      originalId = req.sessionID;
      originalHash = hash(req.session);
      wrapmethods(req.session);
    }
1102965
def set_random_state(state):
    """"""
    randgen.state_set = True
    randgen.setstate(state)

    faker.generator.random.setstate(state)
319800
def random_id(length):
    """"""

    def char():
        """Generate single random char"""

        return random.choice(string.ascii_letters + string.digits)

    return "".join(char() for _ in range(length))
388273
def generate_random(number_of_bytes=None, region=None, key=None, keyid=None,
                    profile=None):
    '''
    
    '''
    conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)

    r = {}
    try:
        random = conn.generate_random(number_of_bytes)
        r['random'] = random['Plaintext']
    except boto.exception.BotoServerError as e:
        r['error'] = __utils__['boto.get_error'](e)
    return r
550216
private function generate(): void
    {
        $this->hexUUID = \sprintf(
            '%s-%s-%s-%s-%s',
            // 8 hex characters
            \bin2hex(\random_bytes(4)),
            // 4 hex characters
            \bin2hex(\random_bytes(2)),
            // "4" for the UUID version + 3 hex characters
            // 0x4000 is 16384 in int
            // 0x4fff is 20479 in int
            \dechex(\random_int(16384, 20479)),
            // (8, 9, a, or b) for the UUID variant 1 plus 3 hex characters
            //  0x8000 is 32768 in int
            //  0xbfff is 49151 in int
            \dechex(\random_int(32768, 49151)),
            // 12 hex characters
            \bin2hex(\random_bytes(6))
        );
    }
459376
def generate(self):
        """"""
        payload = {
            'algorithm': 'HMAC-SHA256'
        }

        if self.data:
            payload['app_data'] = self.data

        if self.page:
            payload['page'] = {}

            if self.page.id:
                payload['page']['id'] = self.page.id

            if self.page.is_liked:
                payload['page']['liked'] = self.page.is_liked

            if self.page.is_admin:
                payload['page']['admin'] = self.page.is_admin

        if self.user:
            payload['user'] = {}

            if self.user.country:
                payload['user']['country'] = self.user.country

            if self.user.locale:
                payload['user']['locale'] = self.user.locale

            if self.user.age:
                payload['user']['age'] = {
                    'min': self.user.age[0],
                    'max': self.user.age[-1]
                }

            if self.user.oauth_token:

                if self.user.oauth_token.token:
                    payload['oauth_token'] = self.user.oauth_token.token

                if self.user.oauth_token.expires_at is None:
                    payload['expires_in'] = 0
                else:
                    payload['expires_in'] = int(time.mktime(self.user.oauth_token.expires_at.timetuple()))

                if self.user.oauth_token.issued_at:
                    payload['issued_at'] = int(time.mktime(self.user.oauth_token.issued_at.timetuple()))

        if self.user.id:
            payload['user_id'] = self.user.id

        encoded_payload = base64.urlsafe_b64encode(
            json.dumps(payload, separators=(',', ':')).encode('utf-8')
        )

        encoded_signature = base64.urlsafe_b64encode(hmac.new(
            self.application_secret_key.encode('utf-8'),
            encoded_payload,
            hashlib.sha256
        ).digest())

        return '%(signature)s.%(payload)s' % {
            'signature': encoded_signature,
            'payload': encoded_payload
        }