[Gambas-user] Array Shuffle method.

Charlie Ogier charlie at cogier.com
Thu Mar 21 16:47:50 CET 2019


Please note the playground uses the 'Stable' version of Gambas

This is my experience of Shuffle http://www.cogier.com/gambas/shuffle2.webm

Charlie

On 21/03/2019 15:29, Tobias Boege wrote:
> On Thu, 21 Mar 2019, T Lee Davidson wrote:
>> On 3/21/19 8:22 AM, Gianluigi wrote:
>>> Hi,
>>> can this be a correct use of the array Shuffle method?
>>>
>>> [code]
>>> Public Sub Main()
>>>
>>>     Dim aBingo As New Byte[]
>>>     Dim iPull As Byte
>>>
>>>     For i As Byte = 0 To 89
>>>       aBingo.Push(i + 1)
>>>     Next
>>>     aBingo.Shuffle()
>>>     iPull = aBingo[aBingo.Max]
>>>     Print "Extract "; iPull; "\n"
>>>     aBingo.Resize(aBingo.Max - 1)
>>>     '-------------------------------
>>>     Print "Checking:"
>>>     aBingo.Sort()
>>>     For Each i In aBingo
>>>       Print i
>>>     Next
>>>
>>> End
>>> [/code]
>>>
>>> Regards
>>> Gianluigi
>> According to the Wiki, Byte[] has a Shuffle method. But, when I try to run your code, I get:
>> "Unknown symbol 'Shuffle' in class 'Byte[]'" Same thing on the Gambas Playground: http://gambas.one/playground/ultra.php
>>
> It's fairly new (added yesterday around noon GMT).
>
>> Other than that, I think your use of the shuffle method would be a correct use. Although, you should be able to simply use:
>>
>> iPull = aBingo.Extract(aBingo.Max)
>>
>> instead of:
>>
>> iPull = aBingo[aBingo.Max]
>> aBingo.Resize(aBingo.Max - 1)
>>
> And .Extract(.Max) is just .Pop() :-)
>
> Regards,
> Tobi
>



More information about the User mailing list