2
A
回答
4
local M, N, tNonFinal, tFinal = 500, 20, {}, {}
math.randomseed(os.time())
for i = 1, N, 1 do
local iRandom = math.random(1, M)
while tNonFinal[iRandom] do
iRandom = math.random(1, M)
end
table.insert(tNonFinal, iRandom, true)
tFinal[i] = iRandom
end
你所需的表會tFinal
。您還可以添加一個條件,其中if M < N then N = M end
+0
非常感謝你! – Eyeball
3
這可能會幫助你...
local myArray = {}
local valueArray = {1,2,3,4,5,6,7,8,9,10} -- let it be the array with values 1,2...M
local index = 0
local isFetched = {}
for i=1,#valueArray do
isFetched[i] = 0
end
local randomValue = 0
local function addTomyArray()
randomValue = math.random(#valueArray)
if(isFetched[randomValue]==0)then
index = index + 1
isFetched[randomValue] = 1
myArray[index] = valueArray[randomValue]
if(index==#valueArray)then
for i=1,#myArray do
print(myArray[i]) -- result : shuffled array
end
end
else
addTomyArray()
end
end
timer.performWithDelay(0,addTomyArray,#valueArray) -- #valueArray
保持編碼........
+0
感謝您的幫助!我得到它的工作= D – Eyeball
相關問題
- 1. Corona中的隨機文本
- 2. Corona sdk不能查看隨機文本
- 3. 如何在Corona上隨機移動我的物體?
- 4. Corona SDK'相機跟隨'在某個點停止?
- 5. 我如何隨機用Corona SDK爲Lua生成數字
- 6. 隨機隨機化項目列表
- 7. 隨機PHP表格
- 8. OpenMP隨機表演?
- 9. Python隨機列表
- 10. 選擇隨機表
- 11. 隨機與隨機
- 12. 如何隨機列表,並通過隨機列表(慶典)
- 13. 更新MySQL表隨着隨機排序
- 14. 更新表隨機數
- 15. 自調整隨機列表
- 16. 另一個表(隨機)
- 17. Three.js隨機點列表
- 18. sql server:更新表隨機
- 19. 更換的隨機列表
- 20. 4x?隨機圖像表php
- 21. 隨機選擇從列表
- 22. REDIS:隨機訪問列表
- 23. 隨機推薦列表VBA
- 24. 隨機化列表在Haskell
- 25. 隨機乘法表 - C#
- 26. Collections.shuffle()是否隨機列表?
- 27. VB.net隨機表格加載
- 28. 隨機化無序列表
- 29. 隨機整數列表
- 30. 打印從隨機列表
然後對您的問題的答案是:「是的,有一種方法可以這樣做。」請檢查[faq#dontask](http://stackoverflow.com/faq#dontask)。 – hjpotter92
我編輯了我的問題。 – Eyeball
相關:http://stackoverflow.com/q/158716 – finnw