User877117016 posted
Are there more than one process accessing this session variable at the same time?
If so you could have potential deadlocks, where there is only one value left and one thread goes into the loop, then another thread goes in, then the second thread adds the value first, and the first thread loops forever.
If not, this might help:
Dim l_intNumbers As New System.Collections.Generic.List(Of String)()
'Random on Questions
Dim RandomClass As New Random()
Dim RandomNumber As Integer If Session("QuestionNums") IsNot Nothing Then l_intNumbers = CType(Session("QuestionNums"), System.Collections.Generic.List(Of String)) End If
Do
RandomNumber = RandomClass.Next(1, count + 1)
Loop While l_intNumbers.Contains(RandomNumber)
' RandomNumber is a number not in the list. add it.
l_intNumbers.Add(RandomNumber)
Session("QuestionNums") = l_intNumbers
If you want a list of randomly sorted numbers 1-10, I like to use something like this:
int[10] a = new int[] for(int i = 0; i < a.Length; i++) { a[i] = i; } int x, y; int tempHolder; Random ran = new Random(); int factor = 2; // or you could make it factor = Math.Log(a.Length) to get O(nlogn) for(int j = 0; j < factor * a.Length; j++) { x = ran.NextInt(a.Length); y = ran.NextInt(a.Length); tempHolder = a[x]; a[x] = a[y]; a[y] = tempHolder; }
What it does is to put 1-10 in an array, then randomly permute them around. The code above changes every character on average almost 4 times.