本帖最后由 ivor 于 2016-2-18 18:03 编辑
回复 1# kkfgef - @echo off&setlocal enabledelayedexpansion
- for /l %%a in (1,1,10) do (
- for /l %%b in (1,1,1000000) do (
- set ran=!random!!random!!random!!random!
- echo !ran:~-9!
- )
- )>%%a.txt
- pause
复制代码
- # python 3.5.1
- # coding:utf-8
- # 功能:随机9位数字前面补0,无重复
-
- import random, os, time,traceback
-
- start_time = time.time()
- num = list(range(10000000))
- random.shuffle(num)
- a = 1
- wFile = open("%s/%d.txt" % (os.path.split(__file__)[0],a ), 'w')
- print("正在写入第%d个文件" % a)
- try:
- for i in range(len(num)):
- num[i] = "%09d" % num[i]
- if i / 1000000 >= a:
- a += 1
- wFile.close()
- wFile = open("%s/%d.txt" % (os.path.split(__file__)[0], a), 'w')
- print("正在写入第%d个文件" % a)
- wFile.write(num[i] + "\n")
- except:
- traceback.print_exc()
- finally:
- wFile.close()
- print("耗时:%d秒" % (time.time() - start_time))
- input("按回车退出")
复制代码 python 10个文本全部写入耗时39s。
CMD 结果就不发了,需要几分钟 |