onestcoder 0 Posted September 18, 2007 I haven't worked with arrays or randoms much, but what I'm working on is a script that will generate a code 8 digits long with numbers and capital letters. 0-9 and A-Z Example: A342D2E4 or: BN234J23 I just need a point in the right direction. Need a website: http://www.iconixmarketing.com Share this post Link to post Share on other sites
weaponx 16 Posted September 18, 2007 sgBox(0,"", genPassword(8)) Func genPassword($length) Dim $array[36] = ['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','0','1','2','3','4','5','6','7','8','9'] $newPassword = "" For $X = 1 to $length $newPassword &= $array[Random (0, 35, 1)] Next return $newPassword EndFunc Share this post Link to post Share on other sites
onestcoder 0 Posted September 18, 2007 O that is GREAT!!!! Thank you Need a website: http://www.iconixmarketing.com Share this post Link to post Share on other sites
weaponx 16 Posted September 18, 2007 An even better version: MsgBox(0,"", genPassword(8)) Func genPassword($length) $array = StringSplit("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789","") $newPassword = "" For $X = 1 to $length $newPassword &= $array[Random (1, $array[0], 1)] Next return $newPassword EndFunc Share this post Link to post Share on other sites
onestcoder 0 Posted September 18, 2007 Yea I like that, Thanks!!! Works Great Need a website: http://www.iconixmarketing.com Share this post Link to post Share on other sites
Guest Posted September 24, 2012 An even better version: MsgBox(0,"", genPassword(8)) Func genPassword($length) $array = StringSplit("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789","") $newPassword = "" For $X = 1 to $length $newPassword &= $array[Random (1, $array[0], 1)] Next return $newPassword EndFunc An even better better version, I hope Func genChars($length) $array = StringSplit("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345678901234567890123456789", "") $num = Random(200, 1000, 1) Dim $array2[$num + 1] For $i = 1 To $num $array2[$i] = $array[Random(1, $array[0], 1)] Next $newPassword = "" For $X = 1 To $length $newPassword &= $array2[Random(1, 200, 1)] Next Return $newPassword EndFunc ;==>genChars Share this post Link to post Share on other sites
kylomas 416 Posted September 24, 2012 onestcoder, Yet another way (not sure if any are better than the others, only different) ; ; ; consolewrite("New Random String = " & _rstr(15) & @lf) func _rstr($string_length) local $str for $i = 1 to $string_length if random(0,1,1) then $str &= chr(random(65,90,1)) Else $str &= chr(random(48,57,1)) EndIf next return $str endfunc kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Share this post Link to post Share on other sites
guinness 1,521 Posted September 24, 2012 What's wrong with what's in the AutoIt Snippets section? ConsoleWrite(_RandomText() & @CRLF) Func _RandomText($iLength = 10) Local $sData = '', $sRandom For $i = 1 To $iLength $sRandom = Random(55, 116, 1) $sData &= Chr($sRandom + 6 * ($sRandom > 90) - 7 * ($sRandom < 65)) Next Return $sData EndFunc ;==>_RandomText UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Share this post Link to post Share on other sites
Spiff59 54 Posted September 24, 2012 An even more betterer version! MsgBox(0, "", Generate_Code(8)) Func Generate_Code($iLen) Local $str For $x = 1 to $iLen $i = Random(48, 83, 1) $str &= Chr($i + ($i > 57) * 7) Next Return $str EndFunc It is at least more fun Share this post Link to post Share on other sites
kylomas 416 Posted September 24, 2012 @spiff59, That is exactly what I was going for but could'nt figure it out. So I would up with a stupid boolean switch to differentiate letter from number. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Share this post Link to post Share on other sites
MvGulik 86 Posted September 24, 2012 ... Random generates 4 bytes. Tossing 3 of those out the window seem like a real waist. ... "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)"Believing what you know ain't so" ...Knock Knock ... Share this post Link to post Share on other sites
JohnQSmith 40 Posted September 25, 2012 You're all a bunch of necrophiliacs. Thread was dead for 5 years until resurrected yesterday. 1 hannes08 reacted to this Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes". Share this post Link to post Share on other sites
FireFox 260 Posted September 25, 2012 You're all a bunch of necrophiliacs. Thread was dead for 5 years until resurrected yesterday.AND like guinness said, there is a thread for snippets OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDFMy Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme makerMy Examples : Capture tool | IP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewerMy Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control Share this post Link to post Share on other sites
JLogan3o13 1,647 Posted September 25, 2012 You're all a bunch of necrophiliacs.You know what they say, "Once you go cold, it never gets old" 2 czardas and Mechaflash reacted to this "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Share this post Link to post Share on other sites