Random Combination

Ask gaming related questions (AHK v1.1 and older)
VladLens
Posts: 2
Joined: 16 Jan 2022, 08:53

Random Combination

Post by VladLens » 16 Jan 2022, 08:59

Can someone help me make this code make a random combination not of 4 numbers, but of 6?

Code: Select all

#SingleInstance Force
#NoEnv
SetBatchLines -1

; Настройки:

Key = F2	; Клавиша - Старт / Пауза.
I := 0		; С какой цифры начать (1 = 0001). Если 0 - случайный ввод пароля.
Wait := 200	; Время задержки после нажатия 'E'.
Wait2 := 1000	; Время задержки после ввода пароля.

; Конец настроек.

Hotkey, % Key, Start, On, UseErrorLevel

If (I = 0)	; Если нужно случайно:
{
 Loop, 9999
  Str .= Format("{:04}", A_Index) "|"	; Создать строку верного содержания (0001-9999).
 Sort, Str, Random D|			; Отсортировать случайно.

 List := Array()	; Создать массив.
 Loop, Parse, Str, |
  List[A_Index]	:= A_LoopField	; Добавить в него строки.
}
Return



Stop:	; Выключить подбор пароля:
Start := (Start > 1 ? 0 : 2)
KeyWait, %A_ThisHotkey%, U
Hotkey, % Key, Start, On, UseErrorLevel
Return


Start:	; [Включить / Продолжить] подбор пароля:
Start := 1

Hotkey, % Key, Off
Hotkey, % Key " Up", Stop, On, UseErrorLevel

KeyWait, %A_ThisHotkey%, U

While % Start && (Abs(I) < 10000)
{
 If (I < 1)	; Если нужно случайно:
 {
  SendInput, E
  Sleep, % Wait

  S := List[Abs(I-1)]

  SendInput, % S
  ToolTip, Пароль: %S%,0,0
  Sleep, % Wait2
  I--
 }
 Else	; Обычный подбор:
 {
  SendInput, E
  Sleep, % Wait

  S := Format("{:04}", I)

  SendInput, % S
  ToolTip, Пароль: %S%,0,0
  Sleep, % Wait2
  I++
 }
}
ToolTip, % "Завершено: " Abs(I),0,0
Return


~Esc:: ToolTip	; Убрать подсказку.

User avatar
boiler
Posts: 16767
Joined: 21 Dec 2014, 02:44

Re: Random Combination

Post by boiler » 16 Jan 2022, 09:17

It takes longer, but to continue with its current approach, replace this line:

Code: Select all

  Loop, 9999
…with this:

Code: Select all

  Loop, 999999

And wherever you see {:04}, replace it with {:06}.

VladLens
Posts: 2
Joined: 16 Jan 2022, 08:53

Re: Random Combination

Post by VladLens » 16 Jan 2022, 10:48

boiler wrote:
16 Jan 2022, 09:17
It takes longer, but to continue with its current approach, replace this line:

Code: Select all

  Loop, 9999
…with this:

Code: Select all

  Loop, 999999

And wherever you see {:04}, replace it with {:06}.
I don't know why, but the script now just writes the letter "E" without numbers. I replaced line 18

Code: Select all

Loop, 9999
to

Code: Select all

Loop, 999999
line 19

Code: Select all

Str .= Format("{:04}", A_Index) "|"
to

Code: Select all

"Str .= Format("{:06} ", A_Index) "|"
and line 64

Code: Select all

S := Format("{:04}", I)
to

Code: Select all

S := Format("{:06}", I)
Did I do everything right?

User avatar
boiler
Posts: 16767
Joined: 21 Dec 2014, 02:44

Re: Random Combination

Post by boiler » 16 Jan 2022, 11:08

No, look carefully at line 19. You said you made it:

Code: Select all

"Str .= Format("{:06} ", A_Index) "|"

It needs to be:

Code: Select all

Str .= Format("{:06}", A_Index) "|"

Did you really put a " at the beginning of the line? It seems that it would have given you an error.

Also, it now takes a lot longer (100 times longer) for it to set up the array because it's going through 999999 numbers instead of 9999. So insert this line before the Return on line 26, and don't start using hotkeys until you get a message saying it's ready:

Code: Select all

MsgBox, Ready! Press OK to begin.

Post Reply

Return to “Gaming Help (v1)”