Login   /   Register

Generate random string

Rate this article
     0 votes, average: 0 out of 50 votes, average: 0 out of 50 votes, average: 0 out of 50 votes, average: 0 out of 50 votes, average: 0 out of 5
Loading ... Loading ...
April 1st, 2008 by daniva

Google Search Results

You arrived here after searching for the following phrases:

Click a phrase to jump to the first occurrence, or return to the search results.

Sometimes we need to generate a random string to use in our tests. The following code generates a random string of alpha characters. You can extend the function to generate additional strings.

Function RandomString( ByVal strLen ) 
    Dim str
    Const LETTERS = "abcdefghijklmnopqrstuvwxyz0123456789" 
    For i = 1 to strLen
        str = str & Mid( LETTERS, RandomNumber( 1, Len( LETTERS ) ), 1 )
    Next
    RandomString = str
End Function

Posted in VBScript

2 Responses to “Generate random string”

  1. Mohamed Ali Says:

    [+]

    You can get a similar result using the "String" function and the Character Set, as follows: Function RandString(iLen) For i=1... ...

  2. daniva Says:

    [-]

    Yes….another solution.

Leave a Reply

You must be logged in to post a comment.

This article was viewed 734 times