Lua 生成随机数, 并写入文件

function GetRandomText()
	--math.randomseed( tonumber(tostring(os.time()):reverse():sub(1,6)) )
	math.randomseed(os.time())
	szText = ""
	for i = 1, 1000 do
		nRandomNum = tostring(math.random()):sub(3,6)
		--nRandomNum = math.random() * 1000
		szText = szText..nRandomNum.."\n"
	end
	return szText;
end

function WriteText(szFileName,szContent,szType)
	f = debug.traceback(io.open(szFileName,szType))
	f:write(szContent)
	f:close()
end

IN_TXT_NAME = "in.txt"
function GetInTxt()
	szContent = GetRandomText()
	szType = "w"
	WriteText(IN_TXT_NAME,szContent,szType)
end

function Main()
	GetInTxt()
end


Main()

你可能感兴趣的:(CodeNote,Lua)