Jump to content

Recommended Posts

Posted

Have a look at the help - under the index of Random.

You should find all you need to know about random numbers and letters (both cases).

It uses the format:

Random ( [Min [, Max [, Flag]]] )

Where:

Min [optional] The smallest number to be generated. The default is 0.

Max [optional] The largest number to be generated. The default is 1.

Flag [optional] If this is set to 1 then an integer result will be returned. Default is a floating point number.

So you can incorporate the range of numbers / letters (syntax in help) required.

Posted

I'll show you how to send a string of random letters&numbers if you want too..

$nr=5; Number of chars in total
$s=""; String you will be sending
for $i=1 to $nr
if Random()<0.5 then
$s&=Random(0,9,1); Send random digit
else
$s&=Chr(Random(65,90,1)); Send random uppercase letter..if you don't need uppercase, just put in Chr(Random(97,122,1)) or whatever range you want
endif
Next; Ended loop..string is in $s
Send($s); Send string..
; You could make this a func and call it whenever you want to send random strings..

This is off my head..so I don't know if it works..:whistle:..Tell me if it works or not, though :dance:

Quote

Together we might liveDivided we must fall

 

Posted

You could code it yourself using Random and a few little other things... Search "Random" in the helpfile and it shows you how to produce randome numbers and letters...

Or...

You could use my automated method of generating a whole random string with letters and numbers. And thank you Burrop for adding to this generator :whistle:

#include <GUIConstants.au3>
GUICreate("Random Generator", 200, 100)
$Char = GUICtrlCreateInput("# of char's. to output", 10, 20, 140, 20)
$Make = GUICtrlCreateButton("Generate", 10, 61, 50, 25)
$PW = GUICtrlCreateEdit("", 70, 63.5, 125, 20, BitOr($ES_READONLY, $ES_AUTOVSCROLL, $WS_VSCROLL))
$Clear = GUICtrlCreateButton("Clear", 155, 15)
GUICtrlCreateLabel("Output:", 70, 48, 35, 15)
GUICtrlSetState($Char, $GUI_FOCUS)
GUISetState()
While 1 ;loop edited by Burrup to make sure that a digit is entered! 
   $Get = GUIGetMsg()
   Select
      Case $Get = $Make
         If StringIsDigit (GUICtrlRead($Char)) = 0 Then
            MsgBox(0,"Whoops!","Please enter a digit.")
            GUICtrlSetData($Char, "# of char's. to output")
            GUICtrlSetState($Char, $GUI_FOCUS)
         Else
            Generate()
         EndIf
      Case $Get = $Clear
         Clear()
      Case $Get = -3
         Exit
   EndSelect
WEnd

Func Generate();Func Generate () edited by Burrup which made the function even more random! thanks Burrup
   $Read = GUICtrlRead($Char)
   If Not StringIsDigit($Read) Then Return
   $Read = Number($Read)
   GUICtrlSetData($PW, "")
   GUICtrlSetLimit($PW, $Read)
   For $I = 1 To $Read
      $Pass = Chr(Random(Asc("a"), Asc("z"), 1))
      $Ran = Random(1, 2, 1)
      If $Ran = 1 Then
         GUICtrlSetData($PW, $Pass, 1)
         GUICtrlSetData($PW, Random(0, 9, 1), 1)
      Else
         GUICtrlSetData($PW, Random(0, 9, 1), 1)
         GUICtrlSetData($PW, $Pass, 1)
      EndIf
   Next
EndFunc

Func Clear()
   GUICtrlSetData($Char, "", "")
   GUICtrlSetData($Char, "# of char's. to output", 1)
   GUICtrlSetData($PW, "", "")
   GUICtrlSetState($Char, $GUI_FOCUS)
EndFunc
FootbaG
Posted

victt

Ur code didn't work :whistle:

the error was 
line o
$s&=random(0,9,1):send random digit
$s^ERROR

Error: Expected a "=" operator in assignment statement.

Layer that is a good program and does generate random and it looks nice but all i want to be able to do is this

Click send random letter/# combo TAB repeat

then continue with other script functions.

Thank you guys for helping a total newbie.

Posted

Replace $s&=whatever with $s=$s&whatever..

Just a small question but are you using the latest beta?

Quote

Together we might liveDivided we must fall

 

Posted

Yep..doesn't work with the regular version of autoit..you need beta-flavour..lemme give you a nice compatible version of it..

Quote

Together we might liveDivided we must fall

 

Posted (edited)

Here's the version that doesn't require the beta..Have phun..shift+F4 to start..

$STRINGLENGTH=10
$NUMBER_OF_ITERATIONS=50
Func HotExit()
Exit
EndFunc
Func Start()
Local $str
for $i=1 to $NUMBER_OF_ITERATIONS
Send(GenRandomString($STRINGLENGTH))
next
EndFunc
Func GenRandomString($nr)
Local $s=""; String you will be sending
Local $i
for $i=1 to $nr
if Random()<0.5 then
$s=$s&Random(0,9,1); Send random digit
else
$s=$s&Chr(Random(97,122,1)); Sends random lowercase char
endif
Next; Ended loop..string is in $s
Return $s
EndFunc
;Main program stars here
HotKeySet("+{ESC},"HotExit")
HotKeySet("+{F4}","Start")
while 1; Infinite loop
Sleep(100)
wend

EDIT: Whoops..almost forgot to make a hotkey to exit..

Edited by VicTT
Quote

Together we might liveDivided we must fall

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...