当前位置: 首页>>代码示例>>Python>>正文


Python SystemRandom.sample方法代码示例

本文整理汇总了Python中random.SystemRandom.sample方法的典型用法代码示例。如果您正苦于以下问题:Python SystemRandom.sample方法的具体用法?Python SystemRandom.sample怎么用?Python SystemRandom.sample使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在random.SystemRandom的用法示例。


在下文中一共展示了SystemRandom.sample方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: init_captcha

# 需要导入模块: from random import SystemRandom [as 别名]
# 或者: from random.SystemRandom import sample [as 别名]
def init_captcha():
    dice = SystemRandom()
    normalset, oddballset = dice.sample(current_app.captcha_data, 2)
    normals = dice.sample(normalset, NORMALS)
    oddballs = dice.sample(oddballset - normalset, ODDBALLS)
    united = normals + oddballs
    dice.shuffle(united)
    challenge = ' '.join(united)
    expiry = datetime.today() + AUTHENTICATION_TIME
    session['captcha-answer'] = map(lambda s: s.lower(), oddballs)
    session['captcha-expires'] = expiry
    if 'captcha-quarantine' in session:
        del session['captcha-quarantine']
        session.modified = True
    return {'captcha_expires': str(expiry), 'captcha_challenge': challenge}
开发者ID:JeremyAllenNZ,项目名称:session-testcase,代码行数:17,代码来源:security.py

示例2: new_password

# 需要导入模块: from random import SystemRandom [as 别名]
# 或者: from random.SystemRandom import sample [as 别名]
	def new_password(self, user, passhash):
		"""
		Return new random password
		"""
		chars = '23456qwertasdfgzxcvbQWERTASDFGZXCVB789yuiophjknmYUIPHJKLNM'
		r = SystemRandom()
		return ''.join(r.sample(chars, 8))
开发者ID:cyclefusion,项目名称:szarp,代码行数:9,代码来源:ssconf.py

示例3: __init__

# 需要导入模块: from random import SystemRandom [as 别名]
# 或者: from random.SystemRandom import sample [as 别名]
 def __init__(self, length=16):
     rand = SystemRandom()
     rand_chars = rand.sample(RandomString.charsets,length)
     self.generated_string = "".join(rand_chars)
     
     m = hashlib.md5()
     m.update(self.generated_string)
     self.md5 = m.digest()
开发者ID:serolquo,项目名称:sefs,代码行数:10,代码来源:utils.py

示例4: generate_password

# 需要导入模块: from random import SystemRandom [as 别名]
# 或者: from random.SystemRandom import sample [as 别名]
def generate_password(wordcount, words):
    """Takes a dictionary of words, and selects a password.
    The password has the number of words equal to 'wordcount'.
    The words are separated by spaces."""

    from random import SystemRandom
    rand = SystemRandom()

    return reduce(lambda a, b: a + " " + b,
                  map(lambda key: words[key],
                      rand.sample(words, wordcount)))
开发者ID:mnestis,项目名称:utilities,代码行数:13,代码来源:diceware.py

示例5: simple_dice

# 需要导入模块: from random import SystemRandom [as 别名]
# 或者: from random.SystemRandom import sample [as 别名]
def simple_dice(xs, ys):
	r = SystemRandom()

	x = remove_outliers(np.array(xs), 0, np.max(xs))
	y = remove_outliers(np.array(ys), 0, np.max(ys))

	x.sort()
	y.sort()

	nx = len(x)
	ny = len(y)
	
	darray = np.zeros(50)
	for i in xrange(0,50):
		if nx < ny:
			xprime = x
			yprime = r.sample(y, nx)
			n = float(nx)
		else:
			xprime = r.sample(x, ny)
			yprime = y
			n = float(ny)
		xprime.sort()
		yprime.sort()
		darray[i] = kumar_hassebrook(xprime,yprime)
	
	mu = np.mean(darray)
	sigma = np.std(darray)

	conf_level = 0.99
	alpha = 1-conf_level
	alpha = 1.0 - conf_level
	z_alpha_2 = norm.ppf(1-(alpha/2.0))

	e = z_alpha_2 * sigma/math.sqrt(len(darray))

	return mu+e
开发者ID:gautamdivgi,项目名称:trunc-ll-research,代码行数:39,代码来源:simidx.py

示例6: simpareto

# 需要导入模块: from random import SystemRandom [as 别名]
# 或者: from random.SystemRandom import sample [as 别名]
def simpareto(nvars):
	nvar1 = nvars[0]
	nvar2 = nvars[1]

	p1 = Pareto(2000.0, 2.0)
	p2 = Pareto(2000.0, 1.0)

	x = p1.rnd(nvar1)
	y = p2.rnd(nvar2)

	x.sort()
	y.sort()
	
	if False:
		r = SystemRandom()

		darray = np.zeros(100)
		for i in xrange(0,100):
			yprime = r.sample(y, len(x))
			darray[i] = util.dice(x,yprime)
			return max_conf_est(darray, 0.99)

	return new_similarity_invcdf(x, y)
开发者ID:gautamdivgi,项目名称:trunc-ll-research,代码行数:25,代码来源:simnm.py

示例7: simexp

# 需要导入模块: from random import SystemRandom [as 别名]
# 或者: from random.SystemRandom import sample [as 别名]
def simexp(nvars):
	nvar1 = nvars[0]
	nvar2 = nvars[1]

	r = SystemRandom()
	npr.seed(r.randint(0,1e15))
	x = npr.exponential(30, nvar1)
	npr.seed(r.randint(0,1e15))
	y = npr.exponential(35,nvar2)
	
	if False:
		x.sort()
		y.sort()
	
		darray = np.zeros(100)
		for i in xrange(0,100):
			yprime = r.sample(y, len(x))
			yprime.sort()
			darray[i] = util.dice(x,yprime)
			return max_conf_est(darray, 0.99)


	return new_similarity_invcdf(x,y)
开发者ID:gautamdivgi,项目名称:trunc-ll-research,代码行数:25,代码来源:simnm.py

示例8: len

# 需要导入模块: from random import SystemRandom [as 别名]
# 或者: from random.SystemRandom import sample [as 别名]
            words.add(l)
        wf.close()

    len_words = len(words)
    def count_choices(len_words, word_count):
        if word_count == 1: return len_words
        assert word_count > 1
        return len_words * count_choices(len_words - 1, word_count - 1)

    choices = count_choices(len_words, word_count)
    choices_desc = '%2d*[%d words (%d-%d letters) from %s]' % (
        word_count, len_words, min_word_len, max_word_len,
        ':'.join(words_paths), )
    entropies.append((choices, choices_desc, ))
    if len(entropies) > 1:
        print 'Bit Entropy comparisons'
    entropies.sort()
    for (n, d, ) in entropies:
        print '%5.1f bits - %s' % (math.log(n, 2), d, )

    random = SystemRandom()
    words = random.sample(words, word_count)
    for word in words:
        print word

    print word_separator.join(words)


if __name__ == '__main__':
    main()
开发者ID:thorfi,项目名称:pass-words-py,代码行数:32,代码来源:pass-words.py

示例9: zulilyLogin

# 需要导入模块: from random import SystemRandom [as 别名]
# 或者: from random.SystemRandom import sample [as 别名]
class zulilyLogin(object):
    """.. :py:class:: zulilyLogin
        login, check whether login, fetch page.
    """
    def __init__(self):
        """.. :py:method::
            variables need to be used
        """
        self.login_url = 'https://www.zulily.com/auth'
        self.badpage_url = re.compile('.*zulily.com/z/.*html')
        self.rd = SystemRandom()
        self.conf = ConfigParser.ConfigParser()
        self.data = {
            'login[username]': get_login_email('zulily'),
            'login[password]': login_passwd
        }
        self.current_email = self.data['login[username]']
        # self.reg_check = re.compile(r'https://www.zulily.com/auth/create.*') # need to authentication
        self._signin = {}

    def create_new_account(self):
        regist_url = 'https://www.zulily.com/auth/create/'
        regist_data = {
            'firstname': 'first',
            'lastname': 'last',
            'email': ''.join( self.rd.sample(alphabet, 10) ) + '@gmail.com',
            'password': login_passwd,
            'confirmation': login_passwd,
        }
        ret = req.post(regist_url, data=regist_data)
        return ret.url, regist_data['email']

    def change_username(self):
        """
        Already signed up.
        https://www.zulily.com/auth/?email=abcd1234%40gmail.com&firstname=first&lastname=last


        Could not process your sign up. Please try again.
        https://www.zulily.com/auth/create/?email=tty1tty1%40gmail.com&firstname=first&lastname=last
        """
        returl, email = self.create_new_account()
        times = 0
        while returl.startswith('https://www.zulily.com/auth/'):
            returl, email = self.create_new_account()
            times += 1
            if times >= 3:
                time.sleep(600)
                times = 0

        self.conf.read( os.path.join(os.path.dirname(__file__), '../common/username.ini') )
        self.conf.set('username', DB, email)
        self.conf.write(open(os.path.join(os.path.dirname(__file__), '../common/username.ini'), 'w'))
        return email


    def whether_itis_badpage(self, url):
        if self.badpage_url.match(url):
            self.logout_account()
            email = self.change_username()
            self.current_email = email
            self.login_account()
            return True
        else: return False

    def login_account(self):
        """.. :py:method::
            use post method to login
        """
        self.data['login[username]'] = self.current_email
        req.post(self.login_url, data=self.data)
        self._signin[self.current_email] = True

    def logout_account(self):
        req.get('https://www.zulily.com/auth/logout/')

    def check_signin(self, username=''):
        """.. :py:method::
            check whether the account is login
        """
        if username == '':
            self.logout_account()
            self.login_account()
        elif username not in self._signin:
            self.current_email = username
            self.logout_account()
            self.login_account()
        else:
            self.current_email = username

    def fetch_page(self, url):
        """.. :py:method::
            fetch page.
            check whether the account is login, if not, login and fetch again
        """
        ret = req.get(url)
        time.sleep(SLEEP)

        if self.whether_itis_badpage(ret.url):
            ret = req.get(url)
#.........这里部分代码省略.........
开发者ID:mobishift2011,项目名称:amzn,代码行数:103,代码来源:server.py


注:本文中的random.SystemRandom.sample方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。