无为清净楼资源网 Design By www.qnjia.com
外国人写的一个class,这么一点小小的应用,除非有特殊需求,还没有必要模块化。
用asp产生一个随机数。
<%
''**************************************************************************
'' CLASS: cRandom
'' Calls randomize to seed the random number generator.
'' Provides functions for returning ranged random integers or arrays of
'' ranged random integers.
'' Calling randomize to seed the random number generator at the time the
'' class is created seemed like a reasonable thing to do.
private sub Class_Initialize()
'' Check the VBScript documentation for the specifics relating
'' to the Randomize function
Randomize
end sub
'' Terminate doesn''t need to do anything for this class
private sub Class_Terminate()
end sub
''**********************************************************************
'' FUNCTION: RangedRandom
'' PARAMETER: lowerBound, the lowest allowable number to return
'' PARAMETER: upperBound, the highest allowable number to return
'' RETURNS: A random integer between lowerBound and UpperBound,
'' inclusive
''**********************************************************************
public function RangedRandom( lowerBound, upperBound )
RangedRandom = CInt((upperBound - lowerBound) * Rnd + lowerBound)
end function
''**********************************************************************
'' FUNCTION: RangedRandomArray
'' PARAMETER: lowerBound, the lowest allowable number to return
'' PARAMETER: upperBound, the highest allowable number to return
'' PARAMETER: arraySize, zero based number specifying the size of the array
'' PARAMETER: duplicates, true or false to indicate whether duplicate
'' resize the tempArray to hold the number of elements passed in the
'' arraySize parameter
redim tempArray(arraySize)
'' This is a loop counter, set it to 0
filledElements = 0
'' loop until filledElements is equal to the arraySize + 1
do until filledElements = arraySize + 1
'' Call the RangedRandom function with the lowerBound and upperBoundparameters
tempValue = RangedRandom( lowerBound, upperBound )
'' Handle the case where we don''t want duplicate values
if duplicates = false then
badValue = false
for i = 0 to UBound(tempArray)
'' check if the new random value already exists in the array
'' if it does set the badValue flag to true and break out of the loop
if tempValue = tempArray(i) then
badValue = true
exit for
end if
next
if badValue = false then
tempArray(filledElements) = tempValue
filledElements = filledElements + 1
end if
else
'' Handle the case where duplicate values in the array are acceptable
tempArray(filledElements) = tempValue
filledElements = filledElements + 1
end if
loop
'' return the array
RangedRandomArray = tempArray
end function
end class
%>
<%
'' All the code that follows is example code showing the use of the
'' cRandom class.
dim objRandom
dim flip
dim randomArray
dim rowsToTest
dim i, j
'' create an instance of our class
set objRandom = new cRandom
'' set the number of iterations that we want to test
rowsToTest = 10
'' "toggle" to determine whether or not we set the bgcolor of the table row
flip = true
'' Start the table
Response.Write "<table border=0 cellpadding=1 cellspacing=1>"
for j = 0 to rowsToTest
'' We''ll alternate the bgcolor of the table rows based on the
'' value of the flip variable
if flip then
Response.Write "<tr bgcolor=LightGrey>"
else
Response.Write "<tr>"
end if
'' Call the RangedRandomArray function for testing purposes
randomArray = objRandom.RangedRandomArray( 1, 10)
用asp产生一个随机数。
<%
''**************************************************************************
'' CLASS: cRandom
'' Calls randomize to seed the random number generator.
'' Provides functions for returning ranged random integers or arrays of
'' ranged random integers.
'' Calling randomize to seed the random number generator at the time the
'' class is created seemed like a reasonable thing to do.
private sub Class_Initialize()
'' Check the VBScript documentation for the specifics relating
'' to the Randomize function
Randomize
end sub
'' Terminate doesn''t need to do anything for this class
private sub Class_Terminate()
end sub
''**********************************************************************
'' FUNCTION: RangedRandom
'' PARAMETER: lowerBound, the lowest allowable number to return
'' PARAMETER: upperBound, the highest allowable number to return
'' RETURNS: A random integer between lowerBound and UpperBound,
'' inclusive
''**********************************************************************
public function RangedRandom( lowerBound, upperBound )
RangedRandom = CInt((upperBound - lowerBound) * Rnd + lowerBound)
end function
''**********************************************************************
'' FUNCTION: RangedRandomArray
'' PARAMETER: lowerBound, the lowest allowable number to return
'' PARAMETER: upperBound, the highest allowable number to return
'' PARAMETER: arraySize, zero based number specifying the size of the array
'' PARAMETER: duplicates, true or false to indicate whether duplicate
'' resize the tempArray to hold the number of elements passed in the
'' arraySize parameter
redim tempArray(arraySize)
'' This is a loop counter, set it to 0
filledElements = 0
'' loop until filledElements is equal to the arraySize + 1
do until filledElements = arraySize + 1
'' Call the RangedRandom function with the lowerBound and upperBoundparameters
tempValue = RangedRandom( lowerBound, upperBound )
'' Handle the case where we don''t want duplicate values
if duplicates = false then
badValue = false
for i = 0 to UBound(tempArray)
'' check if the new random value already exists in the array
'' if it does set the badValue flag to true and break out of the loop
if tempValue = tempArray(i) then
badValue = true
exit for
end if
next
if badValue = false then
tempArray(filledElements) = tempValue
filledElements = filledElements + 1
end if
else
'' Handle the case where duplicate values in the array are acceptable
tempArray(filledElements) = tempValue
filledElements = filledElements + 1
end if
loop
'' return the array
RangedRandomArray = tempArray
end function
end class
%>
<%
'' All the code that follows is example code showing the use of the
'' cRandom class.
dim objRandom
dim flip
dim randomArray
dim rowsToTest
dim i, j
'' create an instance of our class
set objRandom = new cRandom
'' set the number of iterations that we want to test
rowsToTest = 10
'' "toggle" to determine whether or not we set the bgcolor of the table row
flip = true
'' Start the table
Response.Write "<table border=0 cellpadding=1 cellspacing=1>"
for j = 0 to rowsToTest
'' We''ll alternate the bgcolor of the table rows based on the
'' value of the flip variable
if flip then
Response.Write "<tr bgcolor=LightGrey>"
else
Response.Write "<tr>"
end if
'' Call the RangedRandomArray function for testing purposes
randomArray = objRandom.RangedRandomArray( 1, 10)
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
2024年11月16日
2024年11月16日
- 第五街的士高《印度激情版》3CD [WAV+CUE][2.4G]
- 三国志8重制版哪个武将智力高 三国志8重制版智力武将排行一览
- 三国志8重制版哪个武将好 三国志8重制版武将排行一览
- 三国志8重制版武将图像怎么保存 三国志8重制版武将图像设置方法
- 何方.1990-我不是那种人【林杰唱片】【WAV+CUE】
- 张惠妹.1999-妹力新世纪2CD【丰华】【WAV+CUE】
- 邓丽欣.2006-FANTASY【金牌大风】【WAV+CUE】
- 饭制《黑神话》蜘蛛四妹手办
- 《燕云十六声》回应跑路:年内公测版本完成95%
- 网友发现国内版《双城之战》第二季有删减:亲亲环节没了!
- 邓丽君2024-《漫步人生路》头版限量编号MQA-UHQCD[WAV+CUE]
- SergeProkofievplaysProkofiev[Dutton][FLAC+CUE]
- 永恒英文金曲精选4《TheBestOfEverlastingFavouritesVol.4》[WAV+CUE]
- 群星《国风超有戏 第9期》[320K/MP3][13.63MB]
- 群星《国风超有戏 第9期》[FLAC/分轨][72.56MB]