调用方法:RndNum(1) //这里数是几,就是抽几个数
public string RndNum(int VcodeNum) { UserInfo ui = (UserInfo)Session["UserInfo"]; DataTable dt; string jiang = ""; int temp = -1; DataTable table = EntityForum.GetWordNameById(" wordParentId != 0 and wordRemark1 != '0'"); //这里是数据源可以是数组等,我这儿是在数据库的数 Random rand = new Random(); for (int g = 1; g < VcodeNum + 1; g++) { if (temp != -1) { rand = new Random(g * temp * unchecked((int)DateTime.Now.Ticks)); } int t = rand.Next(7);//这里是数据源的下标 if (temp != -1 && temp == t) { return RndNum(VcodeNum); } temp = t; jiang = table.Rows[t]["wordName"].ToString(); } return jiang; }