Problem with Rnd Function

Problem with Rnd Function

am 28.06.2007 08:56:42 von 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








New Page 1











rand1.asp








New Page 1





<%
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))
%>


Question<<%=k%>> <
%=rs(0)%>



(a)<%=trim(rs(1))%>
"checkbox" name = chk value="<%=trim(rs(1))%>" >
(b)<%=trim(rs(2))%>


(c)<%=trim(rs(3))%>
(d)<%=trim(rs(4))%>


<%
'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
%>



<%
next
response.write("Answer " & ans)
Session("rt_ans") = ans
%>





rand2.asp







New Page 1



<%
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)
%>



Re: Problem with Rnd Function

am 28.06.2007 10:24:00 von Anthony Jones

wrote in message
news:1183013802.671240.75050@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.

Re: Problem with Rnd Function

am 28.06.2007 16:29:33 von Dave Anderson

vinodkus@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.

Re: Problem with Rnd Function

am 30.06.2007 07:54:42 von vinodkus

On 28 Jun, 13:24, "Anthony Jones" wrote:
> wrote in message
>
> news:1183013802.671240.75050@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