外國人寫的一個class,這麼一點小小的應用,除非有特殊需求,還沒有必要模塊化。
用asp產生一個隨機數。
<%
''**************************************************************************
''CLASS:cRandom
''Callsrandomizetoseedtherandomnumbergenerator.
''Providesfunctionsforreturningrangedrandomintegersorarraysof
''rangedrandomintegers.
''Callingrandomizetoseedtherandomnumbergeneratoratthetimethe
''classiscreatedseemedlikeareasonablethingtodo.
privatesubClass_Initialize()
''ChecktheVBScriptdocumentationforthespecificsrelating
''totheRandomizefunction
Randomize
endsub
''Terminatedoesn''tneedtodoanythingforthisclass
privatesubClass_Terminate()
endsub
''**********************************************************************
''FUNCTION:RangedRandom
''PARAMETER:lowerBound,thelowestallowablenumbertoreturn
''PARAMETER:upperBound,thehighestallowablenumbertoreturn
''RETURNS:ArandomintegerbetweenlowerBoundandUpperBound,
''inclusive
''**********************************************************************
publicfunctionRangedRandom(lowerBound,upperBound)
RangedRandom=CInt((upperBound-lowerBound)*Rnd+lowerBound)
endfunction
''**********************************************************************
''FUNCTION:RangedRandomArray
''PARAMETER:lowerBound,thelowestallowablenumbertoreturn
''PARAMETER:upperBound,thehighestallowablenumbertoreturn
''PARAMETER:arraySize,zerobasednumberspecifyingthesizeofthearray
''PARAMETER:duplicates,trueorfalsetoindicatewhetherduplicate
''resizethetempArraytoholdthenumberofelementspassedinthe
''arraySizeparameter
redimtempArray(arraySize)
''Thisisaloopcounter,setitto0
filledElements=0