0
Dim r As New Random
Dim A(2) As String
A(0) = "A"
A(1) = "B"
A(2) = "C"
MsgBox(A(r.Next(0,3)) & "," & A(r.Next(0,3)) & "," & A(r.Next(0,3)))

I want to see in the result one of the following rows:

A,B,C
A,C,B
C,B,A
C,A,B
B,A,C
B,C,A
2
  • 1
    What do you mean "without repeat"? Commented Jun 5, 2015 at 11:37
  • You need to shuffle the array then access each element one at a time, or just use String.Join() Commented Jun 5, 2015 at 11:39

1 Answer 1

2

Sort the array in a random order and then go to 0, 1, 2.

Dim r As New Random
Dim A(2) As String
A(0) = "A"
A(1) = "B"
A(2) = "C"

A = A.OrderBy(Function() r.Next).ToArray()

MsgBox(A(0) & "," & A(1) & "," & A(2)
Sign up to request clarification or add additional context in comments.

2 Comments

you need to have it being A = A.OrderBy(Function() rnd.Next)
@SophairkChhoiy: if an answer solved your problem you should accept it so that other people will know the problem is solved.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.