B4J=true Group=Default Group ModulesStructureVersion=1 Type=Class Version=10 @EndOfDesignText@ Sub Class_Globals Dim population As List Dim sortedIndexTemp As List End Sub 'Initializes the object. You can add parameters to this method if needed. Public Sub Initialize End Sub 'Resumable Subs (wait for / sleep) in server handlers 'Resumable subs can only work when there is a message queue. 'By default, server handlers end when the Handle sub is completed. They do not create a message loop. 'If you want to wait for an event then you need to call StartMessageLoop and later StopMessageLoop. 'https://www.b4x.com/android/forum/threads/resumable-subs-wait-for-sleep-in-server-handlers.81833/ Sub Handle(req As ServletRequest, resp As ServletResponse) Log("##############################################################") Log("############# GA/Handle ########################") Log("##############################################################") resp.ContentType = "text/html" Dim l0 As List l0.Initialize2(Array As Int(1,2,3,4,5)) resp.Write($"${Shuffle(l0)}"$) End Sub Sub genInitialPopulation(population1 As List) ' Mandamos population en blanco y regresamos 128 (popSize) variaciones. End Sub 'Generate random string array Sub ShuffleArray(StringArray() As String) Dim ArrayVal As String Dim Random As Int For i = 0 To StringArray.Length - 1 Random = Rnd(i, StringArray.Length) ArrayVal = StringArray(i) StringArray(i) = StringArray(Random) StringArray(Random) = ArrayVal Next End Sub 'Generate random string array Sub Shuffle(l As List) As List Dim tmpVal As String Dim Random As Int Private l1 As List l1.Initialize For i = 0 To l.Size - 1 Random = Rnd(i, l.Size) tmpVal = l.get(i) l1.InsertAt(i, l.get(Random)) l1.InsertAt(Random, tmpVal) Next Return l1 End Sub