2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > 随机生成一个质数的python代码_使用质数生成随机密码

随机生成一个质数的python代码_使用质数生成随机密码

时间:2022-04-25 23:38:23

相关推荐

随机生成一个质数的python代码_使用质数生成随机密码

我正在做一个大学项目,从打印两个给定输入之间的所有质数开始。后来有人告诉我,它必须与我的课程,网络管理有关,所以我想在我的脚本末尾添加一个密码生成器(用于网络安全)

我把所有的代码都写出来了,但是我有一个问题,就是它不能在我打印出来的列表中使用一个随机素数。它只使用最后一个打印出来的数字,我明白为什么,但是不管怎样,我能使它使用一个随机素数,还是我必须把这些数字存储在某个地方?在#A program to count the prime numbers from a given start to a given end

#importing math function

import math

import os, random, string

#Input the number to start counting from

Starting_number = input("Enter the starting number: ")

#Input the number to end the count on.

Ending_number = input("Enter the number you want to count up to: ")

#if Starting_number is less than 0 it will print out a suitable message.

if Starting_number < 0:

print 'Invalid entry, please enter a positiv number. \nWill count from ',Starting_number, 'to 0 and begin prime number count to',Ending_number, '.'

#If Ending_number is less than or equals to 0 then it will print out a suitable message.

if Ending_number <= 0:

print 'Invalid entry on last input \nPlease enter two positive numbers for the count to work.'

#Starting loop as long as the current count is between Starting_number and Ending_number

for num in range(Starting_number, Ending_number):

#

if all(num%i !=0 for i in range(2,num)):

print num

if num >= 1 and num <= 100:

length = 4

chars = string.ascii_letters + string.digits + '!@#$%^&*()'

random.seed = (os.urandom(1024))

print ''.join(random.choice(chars) for i in range(length))

if num >= 101 and num <= 200:

length = (Ending_number / Starting_number) * 5 + 11

if length >= num:

length = num / 100

chars = string.ascii_letters + string.digits + '!@#$%^&*()'

random.seed = (os.urandom(1024))

print ''.join(random.choice(chars) for i in range(length))

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。