文章




首页 留言系统 文章 联系我们 友情链接

infinite-random伪随机数生成算法

头像infinite联盟

【认证:infinite联盟官方账号】


infinite-random算法是由infinite联盟总盟主研究的由python语言实现的伪随机数生成算法,通过将当前时间和复杂的运算程序结合,实现伪随机数生成,该算法目前为1.0版本


现将核心源码放于下方,转载需注明文章链接

from time import *



pi_old="31415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989"
pi_new = pi_old.replace('0',str(7**2))

#%Y-%m-%d %H:%M:%S.%f
def random(x,y):
    s = int(strftime('%S'))
    m = int(strftime('%M'))
    h = int(strftime('%H'))
    if x > y:
        print("Error:" + "\n" + "  The first index must not be larger than tail index(首索引不得大于尾索引)")
    elif x == y:
        print(x)
    elif x == 0 or y == 0 or x > 2147483647 or y > 2147483647:
        print("Error:" + "\n" + "  The first index and tail index must not be 0 or larger than 65536(首索引和尾索引不得为0或大于2147483647)")
    elif len(str(x))== 1 and len(str(y)) == 1:
        print("Error:" + "\n" + "  The number of bits in the first index and the last index cannot be 1 at the same time(首索引和尾索引位数不得同时为1)") 
    else:
        k1 = len(str(x))
        k2 = len(str(y))
        s1 = str(pi_new[s:s*m])
        s2 = int(s1[k1:k2*k1])
        while True:
            if s2 > y:
                s2 -= y * 2
            elif int(s2) < x:
                s2 += x * 2
            elif s2 <= y and s2 >= x:
                break
        print(s2)
while True:
    print("欢迎体验伪随机数生成算法,如您想退出的话在输入栏输入exit即可")
    a = input("请输入首索引")
    b = input("请输入尾索引")
    if a == '' or b == '':
        print("Error:" + "\n" + "  The first index and tail index must not be None(首索引和尾索引不得为空)")
        continue
    elif a == "exit":
        break
    elif b == "exit":
        break
    random(int(a),int(b))
      
大海



2024/3/24 16:20