Luaは乱数を生成し、ファイルに書き込む

670 ワード

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.."
" 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()