Python 生成固定大小的随机数文件

在实验过程中需要生成固定大小的随机数文件来进行覆盖,通过python实现。

`def randomdata_give(size, danwei):
    with open("C:/Users/12590/Desktop/randomdata1/randomdata_128.txt", "w") as f:
        for i in range(1, int(size * danwei * 1024 / 64)):
            f.write(str(random.randint(1000000000000000000000000000000000000000000000000000000000000000,
                                       9999999999999999999999999999999999999999999999999999999999999999)))
        f.close()
randomdata_give(128,1024)`

size为随机数文件大小,danwei为单位(KB,MB)
生成后通过该文件进行随机数覆盖:

with open("C:/Users/12590/Desktop/randomdata/randomdata_1.txt","r") as f:
    msg = f.read()
    f.close()
with open("C:/Users/12590/Desktop/test4mb.txt", "w")as f:
    f.write(msg)
    f.close()

你可能感兴趣的:(Python编程,科研之路)