|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
缺点:正版成本价格贵(盗版就不说了)、不够安全,大多数服务器用windows系统,没有linux安全vbscript|随机<%
**************************************************************************
CLASS:cRandom
Callsrandomizetoseedtherandomnumbergenerator.
Providesfunctionsforreturningrangedrandomintegersorarraysof
rangedrandomintegers.
**************************************************************************
classcRandom
Callingrandomizetoseedtherandomnumbergeneratoratthetimethe
classiscreatedseemedlikeareasonablethingtodo.
privatesubClass_Initialize()
ChecktheVBScriptdocumentationforthespecificsrelating
totheRandomizefunction
Randomize
endsub
Terminatedoesntneedtodoanythingforthisclass
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
randomvaluesareallowedinthearray
RETURNS:AsingledimensionarraysizedtomatchthearraySize
parameter,containingrandomintegersbetweenlowerBoundand
upperBound,inclusive
**********************************************************************
publicfunctionRangedRandomArray(lowerBound,upperBound,arraySize,duplicates)
dimtempArray()
dimfilledElements,tempValue,badValue,i
resizethetempArraytoholdthenumberofelementspassedinthe
arraySizeparameter
redimtempArray(arraySize)
Thisisaloopcounter,setitto0
filledElements=0
loopuntilfilledElementsisequaltothearraySize+1
dountilfilledElements=arraySize+1
CalltheRangedRandomfunctionwiththelowerBoundandupperBoundparameters
tempValue=RangedRandom(lowerBound,upperBound)
Handlethecasewherewedontwantduplicatevalues
ifduplicates=falsethen
badValue=false
fori=0toUBound(tempArray)
checkifthenewrandomvaluealreadyexistsinthearray
ifitdoessetthebadValueflagtotrueandbreakoutoftheloop
iftempValue=tempArray(i)then
badValue=true
exitfor
endif
next
ifbadValue=falsethen
tempArray(filledElements)=tempValue
filledElements=filledElements+1
endif
else
Handlethecasewhereduplicatevaluesinthearrayareacceptable
tempArray(filledElements)=tempValue
filledElements=filledElements+1
endif
loop
returnthearray
RangedRandomArray=tempArray
endfunction
endclass
%>
<%
Allthecodethatfollowsisexamplecodeshowingtheuseofthe
cRandomclass.
dimobjRandom
dimflip
dimrandomArray
dimrowsToTest
dimi,j
createaninstanceofourclass
setobjRandom=newcRandom
setthenumberofiterationsthatwewanttotest
rowsToTest=10
"toggle"todeterminewhetherornotwesetthebgcolorofthetablerow
flip=true
Startthetable
Response.Write"<tableborder=0cellpadding=1cellspacing=1>"
forj=0torowsToTest
Wellalternatethebgcolorofthetablerowsbasedonthe
valueoftheflipvariable
ifflipthen
Response.Write"<trbgcolor=LightGrey>"
else
Response.Write"<tr>"
endif
CalltheRangedRandomArrayfunction</p>ASP.NET和ASP的比较,技术上比较已经没什么可说的了.新一代在大部分程度来说当然是比旧一代好了.关键看你对所做软件的理解了.因人而定.会写的话也可能比ASP.NET写得更有效率和更方便重用 |
|