Every combination of letters and numbers

PutterPlace

Active member
Joined
Feb 18, 2008
Messages
37
Programming Experience
1-3
I'm looking for some function to put together every possible combination of letters and number to create a string that is 14 characters long. I have found ways to make every possible combination of letters and numbers seperately. However, I've never run across anything to come up with them together. Every string created must contain letters and numbers.

For example:
vnr21lc2sganen

I just have no idea where to start on this one. Any help would be greatly appreciated.
 
What are you actually trying to achieve?

Are you talking about generating every possible 14 character string using a set of 36 characters (26 letters and 10 digits) with at least one letter and one number in each because thats a lot of strings (36^12)*26*10
 
The purpose might be helpfull to know (see question above)

If you are trying to brute force crack a password, you'd probably better drop the idea to do it with managed code.

If you are trying to CREATE a password, you can simply create a random string and when you are done, check if it contains at least one char and one number. Repeat that until it does.
 
I'm looking for some function to put together every possible combination of letters and number to create a string that is 14 characters long. I have found ways to make every possible combination of letters and numbers seperately. However, I've never run across anything to come up with them together. Every string created must contain letters and numbers.

For example:
vnr21lc2sganen

I just have no idea where to start on this one. Any help would be greatly appreciated.
There are multiple ways of doing this, what's the purpose of generating the string? Are there any other rules it has to have or is it just at least 1 letter and 1 number?
 
I'm not doing it to bruteforce a password or anything. It's just a proof of concept type of thing. I'd like to just be able to learn how to do it in VB.NET. It's a thing of my curiosity...since I've already read of a few ways to do this with numbers and letters seperately. I would just like to be able to combine the two.

@Grimalkyne:
I'm not looking to generate a list of every possible 14 character string using a set of 36 characters (26 letters and 10 digits). I'm just looking for some type of function that will be able to do it.

@ JuggaloBrotha:
The only rules are 1 letter, 1 number, 14 characters total, and all letters are lowercase.
 
This can easily be done using the Random class and a loop. Give it some thought and we can help ya from there.
 
This can easily be done using the Random class and a loop

Doubtfull.
As I understand, he wants to be able to create ANY possible 14 char string that contains of lower case chars and numbers only and always has min 1 char and 1 number.
Doing this with Random() it would take a loooooong time until ANY possible combination has been created.

As an IDEA!
(inspired by the distance counter in a car)
VB.NET:
Public Class String14Builder

    Private Lookup() As Char = "abcdefghijklmnopqrstuvwxyz0123456789".ToCharArray
    Private MainArray(13) As Integer
    Private ArrayOverflow = Lookup.Length

    Public Function NextString() As String

        Dim HasChar As Boolean
        Dim HasNumber As Boolean
        Dim sb As System.Text.StringBuilder
        Dim c As Char

        Do
            HasChar = False
            HasNumber = False
            If Not Advance(MainArray.Length - 1) Then Return String.Empty
            sb = New System.Text.StringBuilder
            For i As Integer = 0 To MainArray.Length - 1
                c = Lookup(MainArray(i))
                If IsNumeric(c) Then
                    HasNumber = True
                Else
                    HasChar = True
                End If
                sb.Append(c)
            Next
        Loop Until HasChar And HasNumber
        Return sb.ToString

    End Function

    Private Function Advance(ByVal idx As Integer) As Boolean

        MainArray(idx) += 1
        If MainArray(idx) = ArrayOverflow Then
            If idx = 0 Then
                Return False
            Else
                MainArray(idx) = 0
                Return Advance(idx - 1)
            End If
        Else
            Return True
        End If

    End Function

End Class

called with:
VB.NET:
Dim c As New String14Builder
        Dim s As String = String.Empty
        Do
            s = c.NextString
        Loop Until s.Length = 0
There is MUCH room for performance improvement. But this (hopfully) should at least work ;)
 
Last edited:
picoflop, unless I'm overlooking something, there's nothing random about your code, wouldn't it generate the same string every time?
 
wouldn't it generate the same string every time?
You know the distance measurment device in your car? Not the funky new digital one. I mean the "old" one, where several plastic wheels are located side by side?
The rightmost wheel rotates ans shows a number from 0 to 9. When it reaches 0 again it will advance the wheel to the left by one. That wheel also rotates from 0 to 9 and advances it's left neighbor.
My code just does the same (ok, some combinations are immediately dropped, because of the 1-char + 1-number rule).
The "counter" is the array "mainarrary" (which has 14 "wheels") and is initialized when a class instance is created. On each call of the function "NextString" the "wheels" are advanced like the old mechanical counter.

Putterplace did not mention a "random" string in his first post, but "any possible" combination according to the given rules.
 
You know the distance measurment device in your car? Not the funky new digital one. I mean the "old" one, where several plastic wheels are located side by side?
The rightmost wheel rotates ans shows a number from 0 to 9. When it reaches 0 again it will advance the wheel to the left by one. That wheel also rotates from 0 to 9 and advances it's left neighbor.
My code just does the same (ok, some combinations are immediately dropped, because of the 1-char + 1-number rule).
The "counter" is the array "mainarrary" (which has 14 "wheels") and is initialized when a class instance is created. On each call of the function "NextString" the "wheels" are advanced like the old mechanical counter.

Putterplace did not mention a "random" string in his first post, but "any possible" combination according to the given rules.
Good point, for some reason I was thinking he needed it to be random but indeed you're right.

And I've been aware of how an odometer works since I was 5 (20 years ago)
 
Back
Top