当前位置: 网学 > 编程文档 > ASP > 正文

ASP中一个用VBScript写的随机数类

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 13/06/17

以下是网学网为您推荐的ASP-asp中一个用VBScript写的随机数类,希望本篇文章对您学习有所帮助。

外国人写的一个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
  • 上一篇资讯: 浅谈ASP中的类
  • 网学推荐

    免费论文

    原创论文

    浏览:
    设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
    版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
    Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
    湘ICP备09003080号