A random number written in VBScript in ASP

zhaozj2021-02-16  86

Demo:

62741618583286538060230833491782217116995395533922514376575829327214661252945029762855211007127772633066757355648498453442968626355802259334956947914666267937531021616356734983608565998581399365657412091167684 <% '********************************************** ************************************ 'Class: Crandom' Calls Randomize to Seed The Random Number Generator. 'Provides Functions for Returning Ranged Random Integers ORRAYS OF 'RANGED RANDOM INTEGERS.' **************************************************** ******************************************** Class Crandom '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 does not need to do anything for this class private sub Class_Terminate () end Sub '********************************************************** ********************** FUNCTION: RANGEDR andom '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' random values ​​are allowed in the array 'RETURNS: A single dimension array sized to match the arraySize' parameter, containing random INTEGERS BETWEEN LOWERBOUND and 'UPPERBOUND, INCLUSIVE' ***************************************************************** ************************************* Public Function Rangedrandomarray (LowerBound, UpperBound, Arraysize, DUPLICATES) DIM TEMPARRAY () DIM FilleDelements, TempValue, badValue, i '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 do not want duplicate va lues 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 ranedrandomarray =

转载请注明原文地址:https://www.9cbs.com/read-12997.html

New Post(0)