日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

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

發布時間:2024/4/19 python 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 随机生成一个质数的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代码_使用质数生成随机密码的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。