onestcoder Posted September 18, 2007 Share 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 Link to comment Share on other sites More sharing options...
weaponx Posted September 18, 2007 Share 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 Link to comment Share on other sites More sharing options...
onestcoder Posted September 18, 2007 Author Share Posted September 18, 2007 O that is GREAT!!!! Thank you Need a website: http://www.iconixmarketing.com Link to comment Share on other sites More sharing options...
weaponx Posted September 18, 2007 Share 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 Link to comment Share on other sites More sharing options...
onestcoder Posted September 18, 2007 Author Share Posted September 18, 2007 Yea I like that, Thanks!!! Works Great Need a website: http://www.iconixmarketing.com Link to comment Share on other sites More sharing options...
Guest Posted September 24, 2012 Share 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 Link to comment Share on other sites More sharing options...
kylomas Posted September 24, 2012 Share 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 Link to comment Share on other sites More sharing options...
guinness Posted September 24, 2012 Share 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 Link to comment Share on other sites More sharing options...
Spiff59 Posted September 24, 2012 Share 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 Link to comment Share on other sites More sharing options...
kylomas Posted September 24, 2012 Share 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 Link to comment Share on other sites More sharing options...
MvGulik Posted September 24, 2012 Share 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 ... Link to comment Share on other sites More sharing options...
JohnQSmith Posted September 25, 2012 Share Posted September 25, 2012 You're all a bunch of necrophiliacs. Thread was dead for 5 years until resurrected yesterday. hannes08 1 Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes". Link to comment Share on other sites More sharing options...
FireFox Posted September 25, 2012 Share 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 Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted September 25, 2012 Moderators Share Posted September 25, 2012 You're all a bunch of necrophiliacs.You know what they say, "Once you go cold, it never gets old" Mechaflash and czardas 2 "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! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now