Problem with Rnd Function

V

vinodkus

When I use Rnd function in asp. It gives the random no but it always
gives the same random number. What is its problem can any body tell
me.
Actually I have to made a program for online examination and question
will be select randomly category wise. It means if any body select G.K
category then only G.K type of question will be selected with three
wrong answer and right answer. But my problem is that selected series
of question is fixed. But it require to change if any body run the
program next time what is my problem? Can any body tell me.
The table that i m using is
in_question(qnum int,
Que_catg varchar,
question varchar,
option_a varchar,
option_b varchar,
option_c varchar,
option_d varchar,
right_ans char,
Question_Date datetime,
Status char
)
Here is my three file rand.asp, rand1.asp, rand2.asp I m giving the
details of my program file wise
rand.asp

<!-- #Include File ="Includes/INDIANCON.INC"-->
<html>

<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<title>New Page 1</title>
</head>

<body>
<form name =form1 method=post action="rand1.asp">
<select name = qtg>

<%
set rs = con.execute("select distinct(que_catg) from in_question")
if not rs.eof then
while not rs.eof
%>
<option value=<%=rs(0)%> ><%=rs(0)%></option>
<%
rs.movenext
wend
end if
%>
</select>
<input type = submit name = submit value = submit>
</form>
</body>

</html>

rand1.asp

<!-- #Include File ="Includes/INDIANCON.INC"-->
<html>

<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<title>New Page 1</title>
</head>

<body>
<form name = form1 method="post" action="rand2.asp">
<script language ="JavaScript">
/*
int cnt = 0;
function CheckAns()
{
if (document.form.chk.value == rt_ans)
{
cnt = cnt + 1;
}
}
*/
</script>
<%
qtg = request.form("qtg")
choice = ""
i = 1
while i < 5
rndnm = Int(Rnd*20) + 1
response.write("Choice" & rndnm)
rndnm1 = "#"&rndnm&"#"
if instr(choice,rndnm1) = 0 then
set rs1 = con.execute("select que_catg from in_question where qnum =
'"&rndnm&"'")
if not rs1.eof then
if rs1(0)= qtg then
choice = choice & rndnm1
response.write("Choice" & choice)
i = i + 1
set rs1 = nothing
end if
end if
end if
wend
choice=replace(choice,"##", " ")
choice=replace(choice,"#", " ")
choice=replace(choice," ", ",")
choice = split(choice,",")
%>
<%
ans = " "
ans1 = ""
k = 1
for j = 0 to ubound(choice)
set rs = con.execute("select question, option_a, option_b, option_c,
option_d, right_ans from in_question where qnum='"&choice(j)&"'" )
if not rs.eof then
'ans = ans & trim(rs(5))
%>

<b><font color="#FF00FF">
<font color="black">Question<<%=k%>></font><font color="green" > <
%=rs(0)%></font>
<br>
(a)<%=trim(rs(1))%></font></b><font color="#FF00FF"><b><input type =
"checkbox" name = chk value="<%=trim(rs(1))%>" >
(b)<%=trim(rs(2))%><input type = "checkbox" name = chk value="<
%=trim(rs(2))%>" >
<br>
(c)<%=trim(rs(3))%><input type = "checkbox" name = chk value="<
%=trim(rs(3))%>">
(d)<%=trim(rs(4))%><input type = "checkbox" name = chk value="<
%=trim(rs(4))%>"> </b></font>

<%
'rt_ans = rs(5)
if trim(rs(1)) = trim(rs(5))then
ans = ans & trim(rs(1)) & ","
end if
if trim(rs(2)) = trim(rs(5))then
ans = ans & trim(rs(2))& ","
end if
if trim(rs(3)) = trim(rs(5))then
ans = ans & trim(rs(3))& ","
end if
if trim(rs(4)) = trim(rs(5))then
ans = ans & trim(rs(4))& ","
end if
k = k + 1
end if
%>
<br><br>
<%
next
response.write("Answer " & ans)
Session("rt_ans") = ans
%>
<input type = submit value=submit name=submit>
</form>
</body>
</html>

rand2.asp
<!-- #Include File ="Includes/INDIANCON.INC"-->
<html>

<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<title>New Page 1</title>
</head>

<body>
<%
marks = 0
rt_ans = Session("rt_ans")
rt_ans = split(rt_ans,",")

chk = Request.form("chk")
chk = split(chk,",")
for i = 0 to ubound(rt_ans) - 1
if trim(rt_ans(i)) = trim(chk(i)) then
marks = marks + 1
end if
next
response.write("Total Marks " & marks)
%>

</body>

</html>
 
A

Anthony Jones

When I use Rnd function in asp. It gives the random no but it always
gives the same random number. What is its problem can any body tell
me.

Use the Randomize statement at the top of your script.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top