can you please help me how to random a series of choices, i actually use case statement but the problem is everytime i run the program the same order of choices is being shown.

Dani AI

Generated

A simple, robust pattern is to treat the choices as a list and permute that list when showing the question, rather than relying on fixed branching that always presents the same order. reported the same-sequence symptom; correctly asked whether the answers are coming from a database — that matters for where the randomization is best applied.

Two common options: let the database return rows in random order (DBMS-dependent: SQL Server commonly uses ORDER BY NEWID(), MySQL uses ORDER BY RAND()), or fetch the answers and shuffle them in the application. Database-level random ordering is convenient but can be inefficient for large sets; shuffling client-side gives full control and keeps correctness mapping simple.

A reliable client-side approach is to store each answer as an object that includes a correctness flag, apply an in-place Fisher–Yates shuffle, bind the shuffled list to the UI, and check the flag when an item is selected. The random generator should be instantiated once and reused across shuffles to avoid repeated sequences.

Class Answer
    Public Property Text As String
    Public Property IsCorrect As Boolean
End Class

Sub Shuffle(Of T)(list As IList(Of T), rnd As System.Random)
    Dim n As Integer = list.Count
    While n > 1
        n -= 1
        Dim k As Integer = rnd.Next(n + 1)
        Dim tmp As T = list(k)
        list(k) = list(n)
        list(n) = tmp
    End While
End Sub

' Example usage: create one Random, build a List(Of Answer), call Shuffle, bind to UI,
' and on selection check answers(selectedIndex).IsCorrect.

Troubleshooting notes: pointed toward seed issues — creating a new RNG repeatedly can cause identical sequences, so use one RNG instance per app. If the order still repeats across runs, log the shuffled order to confirm where the repetition is introduced and ensure shuffling occurs at presentation time rather than at design/compile time.

Recommended Answers

All 5 Replies

can you please help me how to random a series of choices, i actually use case statement but the problem is everytime i run the program the same order of choices is being shown.

What choices to be randomized?

for example i have a question
the choices are
select case answer
case 1
choice a
case 2
choice b
case 3
choice c
case 4
choice d
case 5
choice e
end select

i want to randomize the case 1 t0 5 so that everytime i run the program not only case1 is the will generate first.

for example i have a question
the choices are
select case answer
case 1
choice a
case 2
choice b
case 3
choice c
case 4
choice d
case 5
choice e
end select

i want to randomize the case 1 t0 5 so that everytime i run the program not only case1 is the one will generate first.

for example i have a question
the choices are
select case answer
case 1
choice a
case 2
choice b
case 3
choice c
case 4
choice d
case 5
choice e
end select

i want to randomize the case 1 t0 5 so that everytime i run the program not only case1 is the one will generate first.

Where does your come from? did you store your question in the database? it it is then we can randomized that but if it is coded alredy then arrghhhhh I can't help

I don't know what code you have but here is a trick..
in order to have different random number all you have to do is to put the code Randomize in the main form where the random number is generated. But the problems may occurs here, it is not a major but rather a logical problem.

anyway just put the Randomize code in the form..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.