https://bugs.documentfoundation.org/show_bug.cgi?id=158976

Jean-Pierre Ledure <[email protected]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|[email protected] |[email protected]
                   |desktop.org                 |

--- Comment #5 from Jean-Pierre Ledure <[email protected]> ---
I confirm the bug.
Indeed, the algorithm makes that NO ITEM (not only the last one) in the array
will stay on its own place.
This was tested with next code, a variant of Rafael's one:

Sub TestSuffle
  GlobalScope.BasicLibraries.LoadLibrary("ScriptForge")
  Dim cont(3) As Integer
  ' Try 1000 times
  For i = 1 To 1000
    arr = SF_Array.Shuffle(Array(1, 2, 3, 4))
    For j = 0 To 3
        If arr(j) = j + 1 Then cont(j) = cont(j) + 1
    Next j
  Next i
  MsgBox cont(0) & "," & cont(1) & "," & cont(2) & "," & cont(3)
End Sub

This can be corrected by replacing line
     lRandomIndex = Int(Rnd * (lCurrentIndex - lMin)) + lMin
by
     lRandomIndex = Int(Rnd * (lCurrentIndex - lMin + 1)) + lMin

The TestSuffix() gives then 4 * numbers close to 250, e.g.:
     263,235,238,257
totalling more or less 1000: the number of unmoved items indeed can be 0, 1, 2,
3 or 4 by cycle.

I will post a patch.
Thanks for reporting the bug.

-- 
You are receiving this mail because:
You are the assignee for the bug.

Reply via email to