Random String Generation in BP

sivagelli

Well-Known Member
I am not sure if you have a built-in function to generate a random string. However, you can make use of code stage.

Copy the below code in to Global Code of Initialize:

Code:
Public Function GenerateRandomString(ByRef len As Integer, ByRef upper As Boolean) As String
    Dim rand As New Random()
    Dim allowableChars() As Char = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLOMNOPQRSTUVWXYZ0123456789".ToCharArray()
    Dim final As String = String.Empty
    For i As Integer = 0 To len - 1
        final += allowableChars(rand.Next(allowableChars.Length - 1))
    Next

    Return If(upper, final.ToUpper(), final)
End Function

And Create a Code Stage with
  • Inputs
    • Len of Type Number
    • LorUCase of type Flag
  • Output:
    • randString of type String
  • Code : Call the Function defined in the Global Code area
    • randString = GenerateRandomString(Len, LorUCase)
This Code will return the string of specified length in specified case.
 
Top