|
Post by AnkuLua on Jul 21, 2018 1:12:27 GMT
hello, base on this thread, how to random pull line? exp: from 1.txt : 781938912 988109019 182391839 in app randomize input "988109019" (second line) You can first get all input into a table. Then do what you want. math.random(n) gives a number from 1 to n, included. fileName = scriptPath() .. "1.txt" fh,err = io.open(fileName, "r") if (err) then scriptExit("file opening failed") end
local lineString = {} local lineNum = 0 for line in fh:lines() do lineNum = lineNum + 1 lineString[lineNum] = line end
print (lineString[math.random(lineNum)])
|
|
|
Post by dionvk on Jul 22, 2018 10:31:04 GMT
sry it doest work well to me, i add type(lineString[math.random(lineNum)]), because print doesnt input anything in notepad at nox but when i add type its error it said: result 137 [C]: in function "type" ?: in function "type"
do you other solution? anw why add math.random at print? why not add math.random at lineNum = lineNum + mathrandom() ??
local lineString = {} local lineNum = 0 for line in fh:lines() do lineNum = lineNum + mathrandom() lineString[lineNum] = line end print (lineString[lineNum])
and why when i add print (lineString[lineNum]) it doesnt work?
|
|
|
Post by AnkuLua on Jul 25, 2018 7:07:31 GMT
Please share your script and 1.txt Upload them to cloud drive and share the links.
|
|
|
Post by dionvk on Jul 25, 2018 9:01:37 GMT
ups its work already i change to print and edit .txt file with notepad++ , thx anw for ur great support local lineString = {} local lineNum = 0 for line in fh:lines() do lineNum = lineNum + 1 lineString[lineNum] = line end type (lineString[math.random(lineNum)])
|
|