'--- This code can be in AppStart or where needed.
'--- Button1, Button2, etc variable name for the buttons to be randomly activated.
'--- This array should be Dim'ed after the layout containing the buttons is loaded (since this initializes the buttons).
Dim buttons() As Button = Array As Button (Button1, Button2, Button3, Button4, Button5, Button6, Button7)
ShuffleArray(buttons)
Dim n_buttons As Int = buttons.Length
Dim x As Int
For x = 0 To n_buttons - 1
buttons(x).Enabled = True
Log(buttons(x).Text)
Sleep(5000)
If x > 0 Then
buttons(x-1).Enabled = False
End If
Next
'--- Supporting sub to shuffle an array
'--- From: https://www.b4x.com/android/forum/threads/shuffle-string-of-array.23652/#content
'--- Modded for objects
Sub ShuffleArray(arr() As Object)
' Knuth's Algorithm P
Dim n As Int = arr.Length
Dim r As Int
Dim t As Object
For i = 0 To n - 1
r = Rnd(i, n)
t = arr(i)
arr(i) = arr(r)
arr(r) = t
Next
End Sub