Problem with Rnd Function

Discussion in 'ASP General' started by vinodkus@gmail.com, Jun 28, 2007.

  1. Guest

    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>
    , Jun 28, 2007
    #1
    1. Advertising

  2. <> wrote in message
    news:...
    > 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, Jun 28, 2007
    #2
    1. Advertising

  3. 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, Jun 28, 2007
    #3
  4. Guest

    On 28 Jun, 13:24, "Anthony Jones" <> wrote:
    > <> wrote in message
    >
    > news:...
    >
    > > 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
    , Jun 30, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. James Vanns
    Replies:
    7
    Views:
    7,014
    Evan Carew
    Jan 21, 2004
  2. komal
    Replies:
    6
    Views:
    1,409
    msalters
    Jan 25, 2005
  3. Replies:
    2
    Views:
    896
    Bengt Richter
    Aug 1, 2005
  4. Giannis Papadopoulos

    Function pointer to void function and int function

    Giannis Papadopoulos, Sep 5, 2005, in forum: C Programming
    Replies:
    5
    Views:
    1,218
    Barry Schwarz
    Sep 5, 2005
  5. Andrew Banks

    Oder by Rnd() isn't random

    Andrew Banks, Nov 14, 2003, in forum: ASP General
    Replies:
    6
    Views:
    165
    Bob Barrows
    Nov 17, 2003
Loading...

Share This Page