如何生成随机问题 [英] How to generate Random Question

查看:142
本文介绍了如何生成随机问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好的程序员!我想开发一个应用程序,它将生成随机科学问题供学生回答。



我的问题是如何生成字符串随机问题并设置答案为目标。



请有人给我线索。我很感激!



谢谢

解决方案

我认为一个简单的路径就是存储问题(和相关解决方案)在数据库中,然后在问题表上随机选择一行(例如,您可以为每个问题分配一个数字 id ,然后选择具有<的问题code> id 等于随机生成的数字。)


使用随机函数从表中选择问题



例如:

 选择  top   1  user_Code 来自 tbl_user_registration  order   by  newid()







http://msdn.microsoft.com/en-us/library/cc441928.aspx [ ^ ]


简单易用一个表并添加问题,有三个错误和一个正确的ans与序列号

然后在您的表单中获取最大(序列号)表然后



使用此代码



 '  IN表格加载事件 

dim n,i as 整数


Dim num 作为 随机

i = 1 no_of_questions ' 你想加载表单


n = num。下一步 1 ,max_serial_no)

' 现在你的sql查询

dim sqlqry = 从question_table中选择问题,ans1,ans2,ans3,ans4,rightans,其中serial_no =& n&

' 在你的ans ans中必须与right ans相同并以表格形式获得
' 使用datareader executequery命令


next


Hi Fellow Programmers! please i want to develop an application that will be generating random science questions for the student to answer.

My problem is how do i generate the string random question and set the answers as objectives.

Please somebody should give me clue. I appreciate!

Thanks

解决方案

I think a simple path would be storing the questions (and the relative solutions) in a database and then select randomly a row on the questions table (you may, for instance, assign a numeric id to each question and then choose the question having id equal to a random generated number).


use random function While you Select The Question From Table

Eg:

select top 1 user_Code from tbl_user_registration order by newid()




http://msdn.microsoft.com/en-us/library/cc441928.aspx[^]


Its easy make a table and add question,with three wrong and one right ans with serial no
Then in your form get max(serial no) table then

use this code

'IN form load event 
 
dim n,i as integer


Dim num As New Random

for i = 1 to no_of_questions 'you want to load in form

	  
n =num.Next(1, max_serial_no)

'now your sql query

dim sqlqry = "select question,ans1,ans2,ans3,ans4,rightans from question_table where serial_no = " & n & "" 

'in your ans one ans must be same with right ans and get that in form
'use your datareader executequery command


next


这篇关于如何生成随机问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆