How to generate fixed-size random number files in python

created at 07-30-2021 views: 2

In the course of the experiment, a fixed-size random number file needs to be generated for coverage, which is realized by 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 is the random number file size, unit (KB, MB)
After generation, use this file for random number coverage:

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()
created at:07-30-2021
edited at: 07-30-2021: