random number generator

Results 1 to 3 of 3

Thread: random number generator

  1. #1
    Join Date
    Dec 1969

    Default random number generator

    how can i create random numbers everytime the user hits my site

  2. #2
    Join Date
    Dec 1969

    Default RE: random number generator

    create a file in asp called session.asp. and include it on First line on all the pages which you want to hit. This is based on the session.<BR>&#060;%<BR>FUNCTION IfNull (s)<BR> if IsEmpty(s) or IsNull(s) then<BR> IfNull = " "<BR> ELSE<BR> IfNull = s<BR> End If<BR>END FUNCTION<BR><BR>FUNCTION CS(s)<BR> pos = InStr(s, "&#039")<BR> While pos &#062; 0<BR> s = Mid(s, 1, pos-1) & "`" & Mid(s, pos + 1)<BR> pos = InStr(pos + 2, s, "&#039")<BR> Wend<BR> CS= s <BR>END FUNCTION<BR><BR>FUNCTION CreateSession()<BR> Application.Lock<BR> m_Loop = 1<BR> While m_Loop<BR> Randomize<BR> m_SessionID = Int((32000 - 1000 + 1) * Rnd + 1000)<BR> SQL = "SELECT fieldname FROM table name WHERE fieldname ="&m_SessionID<BR> SET SessRS = conn.execute(SQL)<BR> if SessRS.EOF then<BR> SQL = "INSERT INTO table name(fieldsnames here ) VALUES("")"<BR> conn.execute(SQL)<BR> m_Loop=0<BR> response.redirect("index.asp?ID="&m_SessionID)<BR> End IF<BR> WEND<BR> Application.Unlock<BR>END FUNCTION<BR><BR><BR><BR>If IsObject (Session("Conn")) then<BR> Set Conn = (Session("Conn"))<BR>else<BR> set Conn = Server.CreateObject("ADODB.Connection")<BR> Conn.Open "DSN=;UID=;PWD=" // enter your dsn info here<BR> Set Session("Conn") = Conn<BR>End If<BR><BR><BR>m_SessionID = request("ID")<BR><BR>if m_SessionID = "" then<BR> CreateSession()<BR>ELSE<BR> SQL = "SELECT fieldname FROM table nameWHERE fieldname="&m_SessionID<BR> SET IsAValidSession = Conn.Execute(SQL)<BR> if IsAValidSession.EOF then<BR> CreateSession()<BR><BR> End If<BR>End If<BR>%&#062;

  3. #3
    Skippie Guest

    Default RE: random number generator

    This is a more general answer.<BR><BR>This function will return a random integer from 1 to x.<BR><BR>Function Random(x)<BR>Dim y <BR><BR>y = CInt(Rnd() * x) + 1 <BR>If y = x + 1 Then<BR>y = 1 <BR>End If<BR>Random = y<BR>End Function<BR><BR><BR>The problem is that the same sequence of random numbers will be<BR>generated every time the page is hit. To solve the problem,<BR>use the Randomize() function on the top of the page.<BR><BR>Randomize only has to be called once, and you should always use<BR>it first. It doesn&#039t return a random number, but it sets up a different sequence of random numbers generated.<BR><BR>-- Skippie<BR><BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts