Dynamically Fetch the Random records
-
Hi, I am doing Online Examination. I want to access the 10 records(Questions) randomally and these questions I want to disaply on the form one by one. Because I design the form that contains the next and prev buttons. If we click on next button then next question will be disaply and same for prev button previous question display. Thank you, sjs4u
-
Hi, I am doing Online Examination. I want to access the 10 records(Questions) randomally and these questions I want to disaply on the form one by one. Because I design the form that contains the next and prev buttons. If we click on next button then next question will be disaply and same for prev button previous question display. Thank you, sjs4u
You could use the System.Random class with a constant seed value. This will guarantee that the same random number sequence will be generated everytime. Some semi-pseudo code:
// Which question are they on
int question_number = 0; // This could come from Request[] or a hidden field on the page or something
int.TryParse(Request["question_number"], out question_number);int max_questions = 9;
int seed = 42; // The seed could be set from maybe a student id or user id to ensure the questions are random across students
System.Random rand = new System.Random( seed );int random_question_index = 0;
// Move to the appropriate random question based on which question number they're on
for(int i = 0; i < question_number; i++)
random_question_index = rand.Next(0, max_questions);Something like that might work. Your next and previous buttons just need to set "question_number" appropriately.
- S 50 cups of coffee and you know it's on!
-
Hi, I am doing Online Examination. I want to access the 10 records(Questions) randomally and these questions I want to disaply on the form one by one. Because I design the form that contains the next and prev buttons. If we click on next button then next question will be disaply and same for prev button previous question display. Thank you, sjs4u
Sounds like rather than random records, you want to create a random sequence of records to view. The easy way to do this is to create an array of all possible record numbers, and then use a random number generator to pull numbers out of that sequence into a list.
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
You could use the System.Random class with a constant seed value. This will guarantee that the same random number sequence will be generated everytime. Some semi-pseudo code:
// Which question are they on
int question_number = 0; // This could come from Request[] or a hidden field on the page or something
int.TryParse(Request["question_number"], out question_number);int max_questions = 9;
int seed = 42; // The seed could be set from maybe a student id or user id to ensure the questions are random across students
System.Random rand = new System.Random( seed );int random_question_index = 0;
// Move to the appropriate random question based on which question number they're on
for(int i = 0; i < question_number; i++)
random_question_index = rand.Next(0, max_questions);Something like that might work. Your next and previous buttons just need to set "question_number" appropriately.
- S 50 cups of coffee and you know it's on!
for(int i = 0; i < question_number; i++) { random_question_index = rand.Next(0, max_questions); }
Boya - Badana - Tadilat ve Tamirat Isleri Bir Yudum Kahve Molasi (Coffee) Dügün Nisan ve Gelinlik (wedding) Google Reklamlarinizi Sadece Siz Yönetin Elektrik Proje Tesisat Projesi Çizimi Illere Göre Nakliyat Firmalari Istatistik http://www.evdenevenakliyatbul.com