这是一个产生不重复的随机记录的代码,配合数据库使用,需要什么限制就加进来吧Function GetQ()
Dim strsqlQID,rs,StuID
Randomize()
intRandomNumber = Int (1000*Rnd)+1
StuID = Request.Cookies("StudentID")
If StuID = "" Then StuID = Session("StudentID")
If StuID = "" Then
GetQ = -1
Exit Function
End If
strsqlQID = "select top 1 id from Question Where (ModuleID = " & strModuleID & ") And (id Not In (select QID From " & strTableName & " where StuID = " & StuID & ")) Order By Rnd(" & (-1 * intRandomNumber) & "*id)"
OpenDataBase()
Set rs = cn.Execute(strsqlQID)
If rs.EOF Then
GetQ = -1
Else
GetQ = rs(0)
End If
rs.Close
CloseDataBase()
End Function
下面是生成不重复的随机数,可以用数组替换Function GetFRandomPwd()
Dim str,pwd,j
pwd = ""
Randomize
str = "0123456789abcdefghijklmnopqrstuvwxyz"
For j = 1 To 8
pwd = pwd & Mid(str,Int((36 * Rnd) + 1),1)
Next
pwdSql = "select id from Student Where StuAnsPwd = '" & pwd & "'"
Dim pwdRs,cnn
Set cnn = Server.CreateObject("ADODB.Connection")
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("xxxxxx.mdb")
Set pwdRs = cn.Execute(pwdSql)
If Not pwdRs.EOF Then
pwdRs.Close
Set pwdRs = Nothing
cnn.Close
Set cnn = Nothing
pwd = GetFRandomPwd()
Else
pwdRs.Close
Set pwdRs = Nothing
cnn.Close
Set cnn = Nothing
End If
GetFRandomPwd = pwd
End Function
Dim strsqlQID,rs,StuID
Randomize()
intRandomNumber = Int (1000*Rnd)+1
StuID = Request.Cookies("StudentID")
If StuID = "" Then StuID = Session("StudentID")
If StuID = "" Then
GetQ = -1
Exit Function
End If
strsqlQID = "select top 1 id from Question Where (ModuleID = " & strModuleID & ") And (id Not In (select QID From " & strTableName & " where StuID = " & StuID & ")) Order By Rnd(" & (-1 * intRandomNumber) & "*id)"
OpenDataBase()
Set rs = cn.Execute(strsqlQID)
If rs.EOF Then
GetQ = -1
Else
GetQ = rs(0)
End If
rs.Close
CloseDataBase()
End Function
下面是生成不重复的随机数,可以用数组替换Function GetFRandomPwd()
Dim str,pwd,j
pwd = ""
Randomize
str = "0123456789abcdefghijklmnopqrstuvwxyz"
For j = 1 To 8
pwd = pwd & Mid(str,Int((36 * Rnd) + 1),1)
Next
pwdSql = "select id from Student Where StuAnsPwd = '" & pwd & "'"
Dim pwdRs,cnn
Set cnn = Server.CreateObject("ADODB.Connection")
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("xxxxxx.mdb")
Set pwdRs = cn.Execute(pwdSql)
If Not pwdRs.EOF Then
pwdRs.Close
Set pwdRs = Nothing
cnn.Close
Set cnn = Nothing
pwd = GetFRandomPwd()
Else
pwdRs.Close
Set pwdRs = Nothing
cnn.Close
Set cnn = Nothing
End If
GetFRandomPwd = pwd
End Function
解决方案 »
- js中settimeout函数的问题
- 请推荐几个目前比较好的jquery学习网站,国内、国外均可
- 为什么没有效果呢
- 求一asp.net页面通过iquery ajax定时访问另一asp.net页面
- 解释代码 mn=objMmInfo[cActIdx].mmUrl;的意思
- 循环列出了用户列表,点击用户名弹出的不是对应的名称
- jsp出现问题
- 怎样屏蔽窗口上的前进、后退、地址栏(打开的窗口只有最小化、最大化和关闭)
- 什么时候初始化下拉框
- 请达人帮忙解释下下面这段用来识别浏览器的代码,如何使用?
- 一个页面中有一个DIV(ID为DivID),由于DIV中内容很多,有滚动条,打算在拖动滚动条时记住其位置
- 关于select新增option的问题
Dim strsqlQID,rs,StuID
Randomize()
intRandomNumber = Int (1000*Rnd)+1
StuID = Request.Cookies("StudentID")
If StuID = "" Then StuID = Session("StudentID")
If StuID = "" Then
GetQ = -1
Exit Function
End If
strsqlQID = "select top 1 id from Question Where (ModuleID = " & strModuleID & ") And (id Not In (select QID From " & strTableName & " where StuID = " & StuID & ")) Order By Rnd(" & (-1 * intRandomNumber) & "*id)"
OpenDataBase()
Set rs = cn.Execute(strsqlQID)
If rs.EOF Then
GetQ = -1
Else
GetQ = rs(0)
End If
rs.Close
CloseDataBase()
End Function
下面是生成不重复的随机数,可以用数组替换Function GetFRandomPwd()
Dim str,pwd,j
pwd = ""
Randomize
str = "0123456789abcdefghijklmnopqrstuvwxyz"
For j = 1 To 8
pwd = pwd & Mid(str,Int((36 * Rnd) + 1),1)
Next
pwdSql = "select id from Student Where StuAnsPwd = '" & pwd & "'"
Dim pwdRs,cnn
Set cnn = Server.CreateObject("ADODB.Connection")
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("xxxxxx.mdb")
Set pwdRs = cn.Execute(pwdSql)
If Not pwdRs.EOF Then
pwdRs.Close
Set pwdRs = Nothing
cnn.Close
Set cnn = Nothing
pwd = GetFRandomPwd()
Else
pwdRs.Close
Set pwdRs = Nothing
cnn.Close
Set cnn = Nothing
End If
GetFRandomPwd = pwd
End Function