[Gambas-user] Array Shuffle method.

Tobias Boege taboege at gmail.com
Thu Mar 21 16:29:46 CET 2019


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

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk


More information about the User mailing list