Fix Fisher-Yates implemenation of Lua helper.shuffle (bug #21706)
This commit is contained in:
parent
c1c67f2a57
commit
62b287354f
2 changed files with 4 additions and 2 deletions
|
@ -6,6 +6,8 @@ Version 1.11.11+dev:
|
|||
Micro AIs.
|
||||
* Language and i18n:
|
||||
* Updated translations: German
|
||||
* Miscellaneous and bug fixes:
|
||||
* Fix Fisher-Yates implemenation of Lua helper.shuffle (bug #21706)
|
||||
|
||||
Version 1.11.11:
|
||||
* Add-ons server:
|
||||
|
|
|
@ -385,8 +385,8 @@ function helper.shuffle( t )
|
|||
-- it uses the Fisher-Yates algorithm, also known as Knuth shuffle
|
||||
assert( type( t ) == "table", string.format( "helper.shuffle expects a table as parameter, got %s instead", type( t ) ) )
|
||||
local length = #t
|
||||
for index, value in ipairs( t ) do
|
||||
local random = math.random( 1, length )
|
||||
for index = length, 2, -1 do
|
||||
local random = math.random( 1, index )
|
||||
t[index], t[random] = t[random], t[index]
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue