https://bugs.documentfoundation.org/show_bug.cgi?id=158976
Bug ID: 158976
Summary: The "SF_Array.Shuffle" function does not place the end
of the array at the end of the array
Product: LibreOffice
Version: 7.1.2.2 release
Hardware: All
OS: All
Status: UNCONFIRMED
Severity: normal
Priority: medium
Component: BASIC
Assignee: [email protected]
Reporter: [email protected]
Description:
The "SF_Array.Shuffle" function of Scriptforge library does not place the end
of the array at the end of the array.
Steps to Reproduce:
1. enter the "SF_Array.Shuffle" sample code in the Basic IDE.
https://help.libreoffice.org/latest/ja/text/sbasic/shared/03/sf_array.html?&DbPAR=BASIC&System=WIN#Shuffle
Dim a As Variant
a = SF_Array.Shuffle(Array(1, 2, 3, 4))
' Array "a" is now in random order, f.i. (2, 3, 1, 4)
2. execute the code
Or
Press the Run button of the calc file that contains the attached sample code.
Actual Results:
3. the last "a(3)" in array "a" will never be "4"
Expected Results:
3. there is approximately a 25% chance that the value of "a(3)" will be "4"
Reproducible: Always
User Profile Reset: No
Additional Info:
Basic Code (SF_Array.Shuffle)
lMin = LBound(Array_1D)
lCurrentIndex = UBound(array_1D)
' Initialize the output array
ReDim vShuffle(lMin To lCurrentIndex)
For i = lMin To lCurrentIndex
vShuffle(i) = Array_1D(i)
Next i
' Now ... shuffle !
Do While lCurrentIndex > lMin
lRandomIndex = Int(Rnd * (lCurrentIndex - lMin)) + lMin
vSwapValue = vShuffle(lCurrentIndex)
vShuffle(lCurrentIndex) = vShuffle(lRandomIndex)
vShuffle(lRandomIndex) = vSwapValue
lCurrentIndex = lCurrentIndex - 1
Loop
---
The first swap in the "Do While loop" establishes that the last value in the
array is not the last in the array.
---
Version: 24.8.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: 90b12c9bad55e8f50b75a6d7b68caa27d82cc2b9
CPU threads: 4; OS: Windows 10.0 Build 10240; UI render: Skia/Raster; VCL: win
Locale: ja-JP (ja_JP); UI: ja-JP
Calc: CL threaded
--
You are receiving this mail because:
You are the assignee for the bug.