一考试系统,需要随机在题库里面抽题。小弟用的Access数据库题全放在Question表里 Question里有ID列 1-900 对应900道题目。之前用了
string s=select top 100 question,strA,strB,strC,strD,Pic,strR ,Code from question where ID between 1 and 900 order by rnd(id)insert into Exam (question,strA,strB,strC,strD,Pic,strR,Code) " + s + " 以上方法。随机抽出题目了,但下次运行时 还是抽出和前一次随机抽出的一样的100道题。。 很郁闷。。不知道什么原因。各位有没有什么好的方法可以实现此功能?!在Question中随机抽100题,然后把这100道题插入到Exam表中
(要确保每次运行抽出的100道题目,插入到Exam中后都不同) 这才是关键!!!!!强人们,吃完饭过来看看吧。
string s=select top 100 question,strA,strB,strC,strD,Pic,strR ,Code from question where ID between 1 and 900 order by rnd(id)insert into Exam (question,strA,strB,strC,strD,Pic,strR,Code) " + s + " 以上方法。随机抽出题目了,但下次运行时 还是抽出和前一次随机抽出的一样的100道题。。 很郁闷。。不知道什么原因。各位有没有什么好的方法可以实现此功能?!在Question中随机抽100题,然后把这100道题插入到Exam表中
(要确保每次运行抽出的100道题目,插入到Exam中后都不同) 这才是关键!!!!!强人们,吃完饭过来看看吧。
rnd 函数可以有类似的功能,但是这个的缺点是每次用之前要randomize,否则每次的次序是一样的
order by newid(),产生随机id序列
newId只能在sqlserver里用
select top 100 question,strA,strB,strC,strD,Pic,strR ,Code from question where ID between 1 and 900 order by newid()
randomize是VB语句,楼主用的是VB?
Random ra=new Random(unchecked((int)DateTime.Now.Ticks));
sql语句,加个时间做种子
order by rnd(-1 * ID + time())
你top 100肯定每次取出的值都是一样的
建议你将所有的题都取出来,在C#代码里随机抽取试题
这个说的好