思路:创建文件,循环100000个数,导入文件
import random
import os
file = open('f:\\pycharm\dream\\' + 'data' + '.txt', 'w')
f = open('data.txt', 'w+')
for i in range(100000):
file.write(str(random.randint(1, 100)) + "\n"
本文介绍了一种使用Python批量生成包含10万个随机数的文本文件的方法。通过使用random模块生成1到100之间的随机整数,并将其写入到指定路径的文本文件中,实现数据集的快速创建。
思路:创建文件,循环100000个数,导入文件
import random
import os
file = open('f:\\pycharm\dream\\' + 'data' + '.txt', 'w')
f = open('data.txt', 'w+')
for i in range(100000):
file.write(str(random.randint(1, 100)) + "\n"
4803

被折叠的 条评论
为什么被折叠?