Fix Fisher-Yates implemenation of Lua helper.shuffle (bug #21706)

This commit is contained in:
Alexander van Gessel 2014-03-04 11:32:16 +01:00
parent c1c67f2a57
commit 62b287354f
2 changed files with 4 additions and 2 deletions

View file

@ -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:

View file

@ -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