Nick Vaughn
New Member
- Joined
- Jul 24, 2011
- Messages
- 12
Can anyone help me out on this one. I would like to have a formula for Subsets.
Okay, I have thought about it some more and you are right... 308,915,776 it is. My mistake in selecting permutations was that I forgot the letters can repeat.I make it 26^6 or 308,915,776.
My laptop is telling me it'll take about five and a half hours to generate them to a worksheet.
Since Nick will have to maintain a file of passwords or, in your case, numbers that were used for the first argument, so he can test or check to make sure the generated password has not been used before (as well as test to make sure a claimed password is legitimate), I think he might as well just store the passwords and randomly generate a potential password when needed, check it and, if it is a repeat, geneate another one. With over 308 million possibilities, the chance of duplicating a password once or twice is pretty remote, so the Do..Loop he uses, it will not iterate too many times. Here is a function he can use to randomly generate a password...Rather than list 308M 6-letter passwords from AAAAAA to ZZZZZZ (what a boring parade!), how about a function?
Code:Function Nick(ByVal d As Double, _ Optional iLen As Long = 0) As String Dim avs As Variant avs = Split("A B C D E F G H I J K L M N O P Q R S T U V W X Y Z", " ") Do Nick = avs(d - Int(d / 26) * 26) & Nick d = Int(d / 26) Loop While d > 0# If Len(Nick) < iLen Then Nick = String(iLen - Len(Nick), avs(0)) & Nick End Function
Function Nick2()
Dim X As Long
For X = 1 To 6
Nick2 = Nick2 & Chr(Int(26 * Rnd + 65))
Next
End Function
First of all try the 4-character version of the code. Watch Excel's status bar for progress information. This takes approx 45 seconds to go through the 456,976 permutations.Hey Ruddles,
The combination would defiantly be drafted on an Excel Worksheet; if you can administer some formulas I’ll give them a shoot and give feedback how they work.
[FONT=Fixedsys]Option Explicit[/FONT]
[FONT=Fixedsys][/FONT]
[FONT=Fixedsys]Sub CombineAtoZx4()[/FONT]
[FONT=Fixedsys][/FONT]
[FONT=Fixedsys] Dim ws As Worksheet
Dim n1 As Integer, n2 As Integer, n3 As Integer, n4 As Integer
Dim iRow As Long, iColumn As Long, iCombinations As Long
Dim dStart As Date
Application.StatusBar = ""
Application.ScreenUpdating = False
dStart = Now()
Set ws = ThisWorkbook.Sheets(1)
ws.UsedRange.ClearContents
iCombinations = 0
iRow = 0
iColumn = 1[/FONT]
[FONT=Fixedsys] For n1 = Asc("A") To Asc("Z")
For n2 = Asc("A") To Asc("Z")
For n3 = Asc("A") To Asc("Z")
For n4 = Asc("A") To Asc("Z")
iRow = iRow + 1
If iRow > 100000 Then
ws.Columns(iColumn).EntireColumn.AutoFit
iColumn = iColumn + 1
iRow = 1
Application.StatusBar = Format(iCombinations, "#,###") & " combinations found in " _
& Format(Now() - dStart, "hh:nn:ss")
Application.ScreenUpdating = False
Application.ScreenUpdating = True
End If
ws.Cells(iRow, iColumn) = Chr(n1) & Chr(n2) & Chr(n3) & Chr(n4)
iCombinations = iCombinations + 1
Next n4
Next n3
Next n2
Next n1
ws.Columns(iColumn).EntireColumn.AutoFit
Application.ScreenUpdating = True
MsgBox Format(iCombinations, "#,###") & " combinations found" & Space(10) & vbCrLf & vbCrLf _
& "Run time: " & Format(Now() - dStart, "hh:nn:ss"), vbOKOnly + vbInformation[/FONT]
[FONT=Fixedsys][/FONT]
[FONT=Fixedsys]End Sub
[/FONT]
[FONT=Fixedsys]Option Explicit[/FONT]
[FONT=Fixedsys] [/FONT]
[FONT=Fixedsys]Sub CombineAtoZx5()[/FONT]
[FONT=Fixedsys][/FONT]
[FONT=Fixedsys] Dim ws As Worksheet
Dim n1 As Integer, n2 As Integer, n3 As Integer, n4 As Integer, n5 As Integer
Dim iRow As Long, iColumn As Long, iCombinations As Long
Dim dStart As Date
Application.StatusBar = ""
Application.ScreenUpdating = False
dStart = Now()
Set ws = ThisWorkbook.Sheets(1)
ws.UsedRange.ClearContents
iCombinations = 0
iRow = 0
iColumn = 1[/FONT]
[FONT=Fixedsys]
For n1 = Asc("A") To Asc("Z")
For n2 = Asc("A") To Asc("Z")
For n3 = Asc("A") To Asc("Z")
For n4 = Asc("A") To Asc("Z")
For n5 = Asc("A") To Asc("Z")
iRow = iRow + 1
If iRow > 250000 Then
ws.Columns(iColumn).EntireColumn.AutoFit
iColumn = iColumn + 1
iRow = 1
Application.StatusBar = Format(iCombinations, "#,###") & " combinations found in " _
& Format(Now() - dStart, "hh:nn:ss")
Application.ScreenUpdating = False
Application.ScreenUpdating = True
End If
ws.Cells(iRow, iColumn) = Chr(n1) & Chr(n2) & Chr(n3) & Chr(n4) & Chr(n5)
iCombinations = iCombinations + 1
Next n5
Next n4
Next n3
Next n2
Next n1
ws.Columns(iColumn).EntireColumn.AutoFit
Application.ScreenUpdating = True
MsgBox Format(iCombinations, "#,###") & " combinations found" & Space(10) & vbCrLf & vbCrLf _
& "Run time: " & Format(Now() - dStart, "hh:nn:ss"), vbOKOnly + vbInformation[/FONT]
[FONT=Fixedsys][/FONT]
[FONT=Fixedsys]End Sub[/FONT]
[FONT=Fixedsys]Option Explicit[/FONT]
[FONT=Fixedsys] [/FONT]
[FONT=Fixedsys]Sub CombineAtoZx6()[/FONT]
[FONT=Fixedsys][/FONT]
[FONT=Fixedsys] Dim ws As Worksheet
Dim n1 As Integer, n2 As Integer, n3 As Integer, n4 As Integer, n5 As Integer, n6 As Integer
Dim iRow As Long, iColumn As Long, iCombinations As Long
Dim dStart As Date
Application.StatusBar = ""
Application.ScreenUpdating = False
dStart = Now()
Set ws = ThisWorkbook.Sheets(1)
ws.UsedRange.ClearContents
iCombinations = 0
iRow = 0
iColumn = 1[/FONT]
[FONT=Fixedsys]
For n1 = Asc("A") To Asc("Z")
For n2 = Asc("A") To Asc("Z")
For n3 = Asc("A") To Asc("Z")
For n4 = Asc("A") To Asc("Z")
For n5 = Asc("A") To Asc("Z")
For n6 = Asc("A") To Asc("Z")
iRow = iRow + 1
If iRow > 1000000 Then
ws.Columns(iColumn).EntireColumn.AutoFit
iColumn = iColumn + 1
iRow = 1
Application.StatusBar = Format(iCombinations, "#,###") & " combinations found in " _
& Format(Now() - dStart, "hh:nn:ss")
Application.ScreenUpdating = False
Application.ScreenUpdating = True
End If
ws.Cells(iRow, iColumn) = Chr(n1) & Chr(n2) & Chr(n3) & Chr(n4) & Chr(n5) & Chr(n6)
iCombinations = iCombinations + 1
Next n6
Next n5
Next n4
Next n3
Next n2
Next n1
ws.Columns(iColumn).EntireColumn.AutoFit
Application.ScreenUpdating = True
MsgBox Format(iCombinations, "#,###") & " combinations found" & Space(10) & vbCrLf & vbCrLf _
& "Run time: " & Format(Now() - dStart, "hh:nn:ss"), vbOKOnly + vbInformation[/FONT]
[FONT=Fixedsys][/FONT]
[FONT=Fixedsys]End Sub[/FONT]
[FONT=Fixedsys]Option Explicit[/FONT]
[FONT=Fixedsys][/FONT]
[FONT=Fixedsys]Sub CombineAtoZx2()[/FONT]
[FONT=Fixedsys][/FONT]
[FONT=Fixedsys] Dim ws As Worksheet
Dim n1 As Integer
Dim n2 As Integer
Dim iRow As Long
Set ws = ThisWorkbook.Sheets(1)
ws.UsedRange.ClearContents
iRow = 0
For n1 = Asc("A") To Asc("Z")
For n2 = Asc("A") To Asc("Z")
iRow = iRow + 1
ws.Cells(iRow, "A") = Chr(n1) & Chr(n2)
Next n2
Next n1
ws.Columns("A").EntireColumn.AutoFit
MsgBox "Done: " & iRow & " combinations generated." & Space(10), vbOKOnly + vbInformation[/FONT]
[FONT=Fixedsys]End Sub[/FONT]