The same Random
-
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!
-
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!
-
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!
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 )