濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > ASP中一個(gè)用VBScript寫(xiě)的隨機(jī)數(shù)類(lèi)

ASP中一個(gè)用VBScript寫(xiě)的隨機(jī)數(shù)類(lèi)

熱門(mén)標(biāo)簽:金昌電話機(jī)器人價(jià)格 縣域地圖標(biāo)注打印店 外呼系統(tǒng)API接口 修改地圖標(biāo)注 怎么在地圖標(biāo)注自己 個(gè)人可以辦理400電話么 武夷山旅游地圖標(biāo)注 萊西電子地圖標(biāo)注 鳳臺(tái)百度地圖標(biāo)注店
外國(guó)人寫(xiě)的一個(gè)class,這么一點(diǎn)小小的應(yīng)用,除非有特殊需求,還沒(méi)有必要模塊化。
用asp產(chǎn)生一個(gè)隨機(jī)數(shù)。

''************************************************************************** 
'' 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、vbscript編碼模板
  • 利用vbscript腳本修改文件內(nèi)容,此適用于自動(dòng)化的操作中
  • asp,VBscript語(yǔ)法錯(cuò)誤,史上最全最詳細(xì)最精確
  • vbscript腳本編程教程2利用fso來(lái)進(jìn)行文件操作
  • 使用vbscript腳本在表單中進(jìn)行選擇的代碼
  • 用vbscript腳本實(shí)現(xiàn)返回 IP 配置數(shù)據(jù)的代碼
  • ASP里面令人震撼地Debug類(lèi)(VBScript)
  • 調(diào)試JavaScript/VBScript腳本程序(IE篇)
  • JavaScript/VBScript腳本程序調(diào)試(Wscript篇)
  • 枚舉域內(nèi)計(jì)算機(jī)個(gè)數(shù)vbscript腳本(沒(méi)環(huán)境,沒(méi)測(cè)試)
  • ASP/VBScript中CHR(0)的由來(lái)以及帶來(lái)的安全問(wèn)題分析
  • ASP(VBScript)中整除和取余
  • ASP基礎(chǔ)知識(shí)VBScript基本元素講解
  • ASP基礎(chǔ)入門(mén)第四篇(腳本變量、函數(shù)、過(guò)程和條件語(yǔ)句)

標(biāo)簽:通遼 邢臺(tái) 南京 清遠(yuǎn) 赤峰 涼山 上海 楚雄

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《ASP中一個(gè)用VBScript寫(xiě)的隨機(jī)數(shù)類(lèi)》,本文關(guān)鍵詞  ASP,中,一個(gè),用,VBScript,寫(xiě)的,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《ASP中一個(gè)用VBScript寫(xiě)的隨機(jī)數(shù)類(lèi)》相關(guān)的同類(lèi)信息!
  • 本頁(yè)收集關(guān)于ASP中一個(gè)用VBScript寫(xiě)的隨機(jī)數(shù)類(lèi)的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    瑞昌市| 镇平县| 宁波市| 旅游| 辽宁省| 昌邑市| 会泽县| 会宁县| 肥城市| 禹城市| 万宁市| 琼中| 商水县| 孝感市| 达日县| 兴化市| 南木林县| 蓝田县| 建平县| 湖北省| 义乌市| 民和| 汝阳县| 弥勒县| 赤城县| 新巴尔虎右旗| 桓仁| 黑河市| 安新县| 宣汉县| 威海市| 泽库县| 湘潭县| 大港区| 宣武区| 蓝田县| 贺州市| 东港市| 长顺县| 卢龙县| 东乡县|