canesten
2014-08-09 15:45:55 +08:00
lua实现:
local price = {13,11,10,9,6,5,4,3,2,1}
local balance = 40
function randomFood()
math.randomseed(os.time())
math.random(100)
math.random(100)
math.random(100)
math.random(100)
local result = {}
local num = #price
while balance > 0 do
local rangeLeft = 0
for i = 1, num do
if price[i] <= balance then
rangeLeft = i
break
end
end
if rangeLeft == 0 then
break
end
local randomIndex = math.random(rangeLeft, num)
local randomPrice = price[randomIndex]
balance = balance - randomPrice
table.insert(result, randomPrice)
print(randomPrice)
end
print(balance)
end
randomFood()
楼主拿去玩