Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Dynamically Fetch the Random records

Dynamically Fetch the Random records

Scheduled Pinned Locked Moved ASP.NET
designquestionlounge
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sjs4u
    wrote on last edited by
    #1

    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

    Steve EcholsS C 2 Replies Last reply
    0
    • S 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

      Steve EcholsS Offline
      Steve EcholsS Offline
      Steve Echols
      wrote on last edited by
      #2

      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!

      • S
        50 cups of coffee and you know it's on!
        Code, follow, or get out of the way.
      L 1 Reply Last reply
      0
      • S 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

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        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 )

        1 Reply Last reply
        0
        • Steve EcholsS Steve Echols

          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!

          L Offline
          L Offline
          love_man001
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups