Jump to content

Random Numbers and Characters


onestcoder
 Share

Recommended Posts

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

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

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

  • 5 years later...

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

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

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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

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

... Random generates 4 bytes. Tossing 3 of those out the window seem like a real waist. ...

:shifty:

"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

  • Moderators

You're all a bunch of necrophiliacs.

You know what they say, "Once you go cold, it never gets old" :D

"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

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
 Share

  • Recently Browsing   0 members

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