ASP random string

I have the following ASP functions that builds a string based on randomly generated integer values (and converts them to their corresponding ASCII values).....The functions are working properly, but I need the string to only allow ASCII values in the range of 48 to 122.  Currently the range has no lower limit, only an upper limit.

How can I generate random numbers in the range of 48 to 122 ?  I think it might be possible using modular division.

<%
      function generate()

            dim randomTemp
            dim random

            for i=0 to 10
                  randomTemp = randomNumber(122)
                  random = random & Chr(randomTemp)
            next
            
      generate = random
      end function
      
    function randomNumber(intHighestNumber)
            randomize
            randomNumber = int(rnd * intHighestNumber) + 1
    end function

%>
LVL 2
rburelloAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rockymageeCommented:
122-48 = 74

Find a random number between 1 and 74 then add 48 to it:

<%
FUNCTION randNumber
      maxNumber = 74
      Randomize
      randNumber = INT((74 - 1 + 1) * Rnd) + Low
      Response.Write (randNumber + 48)
END FUNCTION

randNumber()
%>
rockymageeCommented:
Here is the whole code snippet .... you should be able to tweak this to fit your needs.  I have it printing out the random number and corresponding Char for that number to show what it is doing ....

<%
FUNCTION randNumber
      maxNumber = 74
      Randomize
      randNumber = INT((74 - 1 + 1) * Rnd) + Low
      randNumber = randNumber + 48
END FUNCTION

FUNCTION createString
    DIM randomString
    randomString = ""
    FOR i=0 TO 10
        randNumber()
        Response.Write randNumber & "&nbsp;&nbsp;&nbsp;&nbsp;"
        Response.Write Chr(randNumber) & "<br><br>"
    NEXT
END FUNCTION

createString()
%>

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rburelloAuthor Commented:
Great !

Thanks for the help Rocky.  Nice algorithm :)

completed code:

<%
      function generate()

            dim randomTemp
            dim random

            for i=0 to 10
                  randomTemp = randomNumber(97,122)
                  random = random & chr(randomTemp) & randomTemp & chr(10)
            next
            
      generate = random
      end function
      
    function randomNumber(min, max)
   
          dim range
          range = max - min
          
            randomize
            randomNumber = int(range*rnd) + min
    end function

%>
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.