B4J Question 4 numbers in a random order[SOLVED]

Peter Lewis

Active Member
Licensed User
Longtime User
I am trying to make 4 numbers in a random order. They must be unique.

So I have tried using the standard <> (Not equal to) but it does not seem to work but itself. I have put brackets around the formulas to see if i can test it using True/False, does not work

a long ways around this would be to make a list of 4 numbers 1-4 and then randomly take out one number at one position at a time and delete that position , then the next one would only randomise between 3 numbers ect ect . I have done this before but i did not think it was optimal.

This is what I have come up with on the last test , but there are duplicates

Any comments will be appreciated
 

Peter Lewis

Active Member
Licensed User
Longtime User
Have you seen this Thread .. https://www.b4x.com/android/forum/t...rs-in-a-non-repeating-list.97696/#post-617468

There are a few interesting variations submitted by other members,
Thank you
I eventually did this

B4X:
Dim but1 As Int
    Dim but2 As Int
    Dim but3 As Int
    Dim but4 As Int
    
    but1 =Rnd(1,5)
    
    but2 =Rnd(1,5)
        Do While (but2 <> but1) = False
                     but2 = Rnd(1,4)
                    
        Loop
        
    
    but3 =Rnd(1,5)
        Do While (but3 <> but1 And but3 <> but2) = False
                    but3 = Rnd(1,4)
                    
        Loop

    but4 =10-(but1+but2+but3)

    Log(but1)
    Log(but2)
    Log(but3)
    Log(but4)
 
Upvote 0
Top