一段极度DT的代码,利用md5算法产生一段随机数表。不知道干什么用,或许可以在蒙特卡洛方法里使用。

主要是利用系统时间做种子(python的内部time函数),带入到md5函数中,得到一个字符串x,抽取其中的数字(0~9)附加到字符串C中,重新计算x的md5值,直到c的长度达到要求。为了防止陷入循环,对字符串x加了一个空格做微扰。最后,格式输出字符串c。

做了一个大概的统计,每个数字出现的几率大约都在0.1左右,基本符合随机分布,当然,仅限于0~9范围内。

import hashlib,time

f=open('Rom.txt','w')
start=str(time.time())
ALL=8100
c=str()

while len(c)

 当然,可以做一个变换,可以减少每行的输出值,作为一个[0,1)左闭右开区间的一个超长的随机数表。

作者 hsyyf

《利用md5产生随机数表》有4条评论
  1. crypto = require ‘crypto’

    md5 = (s) -> crypto.createHash(‘md5’).update(s).digest()

    exports.tortoiseAndHare = (f,init) ->
    # tortoise = hare = init
    # do go = ->
    # tortoise = f tortoise
    # hare = f f hare
    # go() if tortoise != hare
    # FIXME: stack overflows, no tail-recursion optimization?
    tortoise = f init
    hare = f f init
    while tortoise != hare
    tortoise = f tortoise
    hare = f f hare

    mu = 0
    tortoise = init
    while tortoise != hare
    tortoise = f tortoise
    hare = f hare
    mu++

    len = 1
    hare = f tortoise
    while tortoise != hare
    hare = f hare
    len++
    [len, mu, hare]

    console.log tortoiseAndHare md5, (new Date).toString()

回复 hsyyf 取消回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注