Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Question Randomization in Access DB

 
Olumide Alabi
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please.
I'm writing a Test Engine Software and I have a big issue. I have a large question database about 1000 questions and I need to load 50 random questions for each test instance. i.e Each time a user runs the test, 50 DISTINCT questions will be loaded.

They should not be the same every time and questions that have already been loaded and or answered in an instance of the test should not be displayed again for that instance.

Right now, I have extracted all the questions into a ResultSet, is there a way I can shuffle the questions and select the top 50 into a new ResultSet and use the new ResultSet to administer the test. If it's possible, it'll make my job easier. If not, I'd really appreciate any help I can get. Please explain with sample code so I can properly understand what you're saying.

Thanx

Luminus
 
Alex Wolf
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I would do in your situation, is make 2 Vectors or something, one for keeping track of which random number has already been picked, and one for your 50 questions. Get a random number, and if it isn't in the first vector, add it to both vectors. After you added 50 random numbers to both vectors, use the vector with the 50 numbers as your question base. After the questions have been answered, you can toss the vector with the 50 numbers, and start over. this way your tracking vector keeps a list of which questions have already been answered. the rest is just extracting the question from the ResultSet based on its random row number from your returned array.

 
Olumide Alabi
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, but how do I iterate through the Vector.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This might be one way

load the question numbers 1 to 1000 into an arraylist
shuffle the arraylist

for(int x = 0; x < 50; x++)
{
select * from db where questionNumber = arrayList.get(x) //modify to match data types
create question object from rs
add question object to array, for use in program
}

(assumes there is a field in the db for the question number)
Note: my sql/db stuff is really rusty, so the above might not be the best approach
 
Alex Wolf
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you already have all the Questions in a ResultSet, couldn't you just say



I dont know what type of data you have in your ResultSet. You don't need to go through the tracking vector, its just to keep track of which questions have already been used so they won't get repeated.
 
Olumide Alabi
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Micheal and Alex,
thanx a lot. I'll try this out and see what happens. I'll holla @ u to let you know how it goes.

Thanx again.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!