PDA

View Full Version : questionnaire


ebco
12-24-2002, 11:41 AM
I am making one quiz in asp it's around 10 question
What I a doing is i stored 10 questions with anser with write answer & quetion no in database with the columns accordingly

now i have twenty question & want it come 10 question randomly

can anybody give me better idea or any tutorial where it shows the eg. like this

raf
12-24-2002, 01:25 PM
1. Create a primary key (autoincrementing, starting from 1) in your questions table.
2. Perform a random numer generation (cfr lower). Use the maxID from your database a upperlevel. Lowerlevel = 1. To retrieve the maxID, you can use a statement like : select max(ID) as upperlevel from tablename
3. Each randomly generated number is stored in an array. Before storing them in the array, you could check if that number is already saved in the array. Repeat this until you have 10 different numbers. Select the records where the ID is the same as a record in the array (you can use a subquery to get the values from the array in the selectstatement.) or by using them as conditions

select * from tablename where ID = random1 or ID = random2 ....


Random-function
_____________________________

Description
Returns a random number.
Syntax
Rnd[(number)]
The number argument can be any valid numeric expression.

Remarks
The Rnd function returns a value less than 1 but greater than or equal to 0. The value of number determines how Rnd generates a random number:
If number is Rnd generates
Less than zero The same number every time, using number as the seed.
Greater than zero The next random number in the sequence.
Equal to zero The most recently generated number.
Not supplied The next random number in the sequence.


For any given initial seed, the same number sequence is generated because each successive call to the Rnd function uses the previous number as a seed for the next number in the sequence.

Before calling Rnd, use the Randomize statement without an argument to initialize the random-number generator with a seed based on the system timer.

To produce random integers in a given range, use this formula:

Int((upperbound - lowerbound + 1) * Rnd + lowerbound)

Here, upperbound is the highest number in the range, and lowerbound is the lowest number in the range.

--------------------------------------------------------------------------------

Note To repeat sequences of random numbers, call Rnd with a negative argument immediately before using Randomize with a numeric argument. Using Randomize with the same value for number does not repeat the previous sequence.

--------------------------------------------------------------------------------

ebco
12-26-2002, 06:49 AM
Hi thanks for reply
this is my code column of quizetable are:
Qid (primary key autoincrementing),Qno (from 1 to 10), Question, Ans1,Ans2,Ans3,AnsRight(for right answer among three)


<%@ Language=VBScript %>
<!-- #INCLUDE virtual="/test/include/aspfiles/LoginConnection.asp"-->
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<%
rans=Request.Form("rans")
scr=Request.Form("scr")
qno=Request.Form("qno")
ans=Request.Form("ans")
set conn = Server.CreateObject("ADODB.Connection")
conn.Open "connection string"
if qno = "" then
qno = 0
end if
set rdset = Server.CreateObject("ADODB.Recordset")
sql = "select * from quiztable where Qno = "&qno+1&""
rdset.Open sql,conn

if scr="" then
scr=0
else
if ans=rans then
scr=scr+5
end if
end if

%>
</HEAD>
<BODY>
<script language="javascript" src="/test/include/jsfiles/sitesection.asp"></script>
<%if not(rdset.bof and rdset.eof) then%>
<form name="submitfrm" method="post" action="quizmain.asp">
<table>
<tr>
<td valign="top"><%=rdset("Qno")%><input type="hidden" name="qno" value="<%=rdset("Qno")%>"><input type="hidden" name="scr" value="<%=scr%>"><input type="hidden" name="rans" value="<%=rdset("AnsRight")%>"></td>
<td valign="top" colspan="2"><%=rdset("Question")%></td>
</tr>
<tr>
<td valign="top">&nbsp;</td>
<td valign="top"><input type="Radio" name="ans" value="<%=rdset("Ans1")%>"></td>
<td valign="top"><%=rdset("Ans1")%></td>
</tr>
<tr>
<td valign="top">&nbsp;</td>
<td valign="top"><input type="Radio" name="ans" value="<%=rdset("Ans2")%>"></td>
<td valign="top"><%=rdset("Ans2")%></td>
</tr>
<tr>
<td valign="top">&nbsp;</td>
<td valign="top"><input type="Radio" name="ans" value="<%=rdset("Ans3")%>"></td>
<td valign="top"><%=rdset("Ans3")%></td>
</tr>
<tr>
<td valign="top" colspan="3"><input type="submit" value="Submit" id=submit1 name=submit1></td>
</tr>
</table>
</form>
<%else%>

Your score is <%=scr%>

<%end if%>
</BODY>
</HTML>

can u implement on this code

ebco
12-26-2002, 11:35 AM
Int((upperbound - lowerbound + 1) * Rnd + lowerbound)

this formula is not working To produce random integers in a given range

this is how i am using it :
<%
upperbound = 10
lowerbound = 1
qno = Int((upperbound - lowerbound + 1) * Rnd + lowerbound )
Response.Write "<br>" & qno
%>

but every time on refresh it gives me same result

Mhtml
12-26-2002, 06:52 PM
Place the RANDOMIZE statement on a line of it's own near that code.

raf
12-27-2002, 08:43 AM
ebco,

like Mhtml said. It's also,mentioned in my initial reply

Before calling Rnd, use the Randomize statement without an argument to initialize the random-number generator with a seed based on the system timer.

About implementing it for you: sory. not mutch time at the moment but there might be others here that can spend the time. Anyway, i'll check next week and maybe do it then (if still necesary)

In general: selecting the question randomly is not always a good idee. I worked for 4 years as a screening-expert (developing and maintaining tests) and the big problem with randomly generated tests, is that you can't compaire the testscores of the different users (since everybody gets a different test. even changing the order of the questions influences the testscores). This means you can't even compute mains, norms etc.