Sign in to follow this  
Followers 0
onestcoder

Random Numbers and Characters

14 posts in this topic

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



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

O that is GREAT!!!!

Thank you


Need a website: http://www.iconixmarketing.com

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Yea I like that, Thanks!!! Works Great


Need a website: http://www.iconixmarketing.com

Share this post


Link to post
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

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

An honorory member of The League Against Messy Signatures

Share this post


Link to post
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

Share this post


Link to post
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

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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: 04/09/2015

Share this post


Link to post
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 ;)

Share this post


Link to post
Share on other sites

@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

... 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 ...
 

Share this post


Link to post
Share on other sites

You're all a bunch of necrophiliacs. Thread was dead for 5 years until resurrected yesterday.

1 person likes 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

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_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My 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

You're all a bunch of necrophiliacs.

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

3 people like this

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
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
Sign in to follow this  
Followers 0