Problem with Rnd Function

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>
vinodkus [ Do, 28 Juni 2007 08:56 ] [ ID #1753620 ]

Re: Problem with Rnd Function

<vinodkus [at] gmail.com> wrote in message
news:1183013802.671240.75050 [at] g4g2000hsf.googlegroups.com...
> 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.
Anthony Jones [ Do, 28 Juni 2007 10:24 ] [ ID #1753625 ]

Re: Problem with Rnd Function

vinodkus [at] gmail.com wrote:
> 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.

In addition to what Anthony said, RTFM:
http://msdn2.microsoft.com/en-us/library/e566zd96.aspx




--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
Dave Anderson [ Do, 28 Juni 2007 16:29 ] [ ID #1753629 ]

Re: Problem with Rnd Function

On 28 Jun, 13:24, "Anthony Jones" <A... [at] yadayadayada.com> wrote:
> <vinod... [at] gmail.com> wrote in message
>
> news:1183013802.671240.75050 [at] g4g2000hsf.googlegroups.com...
>
> > 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.

Thanks Anthony For ur help
U have just give me accurate response, that is like a panecea
vinodkus [ Sa, 30 Juni 2007 07:54 ] [ ID #1756411 ]
Webserver » microsoft.public.inetserver.asp.general » Problem with Rnd Function

Vorheriges Thema: email Problem
Nächstes Thema: example code for using insertion point of data