随机生成一个质数的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))
總結
以上是生活随笔為你收集整理的随机生成一个质数的python代码_使用质数生成随机密码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python线性输出_python sk
- 下一篇: websocket python爬虫_p