function split(a,b)
count=0
start = 1
local arry = {}
lastStart = string.find(a,b,start)
if(lastStart~=nil)then
count=count+1
end
table.insert(arry,1,string.sub(a,start,lastStart-1))
while(lastStart~=nil)do
start = string.find(a,b,lastStart+1)
if(start~=nil)then
table.insert(arry,1,string.sub(a,lastStart+1,start-1))
count=count+1
else
table.insert(arry,1,string.sub(a,lastStart+1,string.len(a)))
end
lastStart=start
end
return arry
end
function ReadLine(file)
return file:read("*line")
end
function getTable()
local file = io.open("lua\\1.lua","r")
if(file==nil)then print("Error")end
local arry={}
local data=ReadLine(file)
count = 0
while data~=nil do
count = count + 1
table.insert(arry,split(data,","))
data = ReadLine(file)
end
return arry
end
function getRandomCount()
count = math.random(0,100)
print(count)
return count
end
function Lottery(item,arry)--抽奖
for i=table.getn(arry),1,-1 do
if(tonumber(arry[i][1])>=item)then
return arry[i][2]
end
end
end
math.randomseed(os.time())
local arry = getTable()
local item = {}
for i=1,1000,1 do
item = Lottery(getRandomCount(),arry)
print(item)
end
无,100
倚天剑,80
屠龙刀,50
狼牙棒,10
擀面杖,1