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. The same Random

The same Random

Scheduled Pinned Locked Moved ASP.NET
3 Posts 3 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
    sohighthesky
    wrote on last edited by
    #1

    System.Text.StringBuilder sql = new System.Text.StringBuilder(); for (int i = 1; i <= 3; i++) { DataTable dt = dao.GetQuestionByType(i).Tables[0]; if (dt != null && dt.Rows.Count > 0) { for (int j = 0; j < 5; j++) { Random rd = new Random(j); sql.AppendFormat("insert into TQ_ExamDetail values({0},{1});",temp,(int)dt.Rows[rd.Next(1,dt.Rows.Count)]["TQ_QuestionID"]); } } } Why is random has the same result? Thank you in advance!

    Y C 2 Replies Last reply
    0
    • S sohighthesky

      System.Text.StringBuilder sql = new System.Text.StringBuilder(); for (int i = 1; i <= 3; i++) { DataTable dt = dao.GetQuestionByType(i).Tables[0]; if (dt != null && dt.Rows.Count > 0) { for (int j = 0; j < 5; j++) { Random rd = new Random(j); sql.AppendFormat("insert into TQ_ExamDetail values({0},{1});",temp,(int)dt.Rows[rd.Next(1,dt.Rows.Count)]["TQ_QuestionID"]); } } } Why is random has the same result? Thank you in advance!

      Y Offline
      Y Offline
      Yusuf
      wrote on last edited by
      #2

      you need to seed it first, see here[^]

      Yusuf Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]

      1 Reply Last reply
      0
      • S sohighthesky

        System.Text.StringBuilder sql = new System.Text.StringBuilder(); for (int i = 1; i <= 3; i++) { DataTable dt = dao.GetQuestionByType(i).Tables[0]; if (dt != null && dt.Rows.Count > 0) { for (int j = 0; j < 5; j++) { Random rd = new Random(j); sql.AppendFormat("insert into TQ_ExamDetail values({0},{1});",temp,(int)dt.Rows[rd.Next(1,dt.Rows.Count)]["TQ_QuestionID"]); } } } Why is random has the same result? Thank you in advance!

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

        Because you asked it to be. AKA RTFM.

        Christian Graus Driven to the arms of OSX by Vista. "I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )

        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