ASP Type conversion - from integer to ASCII

I am trying to generate a random string in ASP (not ASP.net).  This is a function that I tried to convert from C#, but I am having trouble going from an integer value, and converting it to it's relative ASCII value.....int 122 type cast to a 'z' and then concatinating each random character to a string.  These two functions right now give me a random number, but I cannon get the string that I want.

      function generate()

            dim randomTemp
            dim random

            for i=0 to 10
                  randomTemp = randomNumber(122)
                  CStr(randomTemp)
                  random = "" & randomTemp
            next
            
      generate = random
      end function
      
    function randomNumber(intHighestNumber)
            randomize
            randomNumber = int(rnd * intHighestNumber) + 1
    end function
LVL 2
rburelloAsked:
Who is Participating?
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.

TimCotteeHead of Software ServicesCommented:
Hi rburello,

You need Chr() rather than Cstr()

Cstr(x) converts a numeric datatype to a string datatype e.g. 122 becomes "122"

Chr(x) returns the ascii char from the list index x e.g., Chr(122) = "z"

Tim Cottee
0
rburelloAuthor Commented:
Still giving me integers.  I am not sure if the algorithm has an error, because I keep getting two character int, when I expect a 10 character int.  I changed the function from CStr to Chr().
0
TimCotteeHead of Software ServicesCommented:
rburello,

     function generate()

          dim randomTemp
          dim random

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

Only saw Cstr and didn't spot that it wasn't actually being assigned to anything!

Tim
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

rburelloAuthor Commented:
OOPS....stupid mistake.  Now it is converting to the ASCII character, but I am only getting back a single character now, instead of a 10 character string

Thanks in advance, Tim
0
TimCotteeHead of Software ServicesCommented:
TimCottee,

               random = random & chr(randomTemp)

Not adding the new char each time, missed that as well!

Tim
0

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 !

Thank you, Tim.  I'm sorry I made you correct such simple errors for me.  Now that that is working, the last part of this function I need is to keep the random numbers in the range of 48 to 122, so it does not put the junk characters into the string (this string will be used in a querystring, by the way).
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.