cypher175 Posted March 29, 2009 Posted March 29, 2009 (edited) how can i generate some random alphanumeric text..?? Edited March 29, 2009 by cypher175
Vindicator209 Posted March 29, 2009 Posted March 29, 2009 Chr(Random(Asc("A"), Asc("Z"), 1)) is that what you are looking for? [center]"When you look at old, classic games like Snake, you often put it off because it's such a simple game, but it's only when you actually try and create your own unique game from scratch, do you finally appreciate those games."[/center][center]Don't ask for answers if you haven't TRIED yet![/center][center]Most answers can be answered in the help file! Use it![/center]
cageman Posted March 29, 2009 Posted March 29, 2009 (edited) i know chr(96) represents a letter. so if you look those up and create random numbers between the letters you want it should be fine? so chr(Random(96,128,1)) for example? just look up that chr function oh i see im too late read above Edited March 29, 2009 by cageman
cypher175 Posted March 29, 2009 Author Posted March 29, 2009 sp how do i generate string that looks like this "A1B4C6D8E9F0G7" ..??
PhilRip Posted March 29, 2009 Posted March 29, 2009 Func _Randomstring($length) $chars= StringSplit("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789","") $String = "" $i=0 Do If $length<=0 then ExitLoop $String &= $chars[Random(1,$chars[0])] $i += 1 Until $i = $length Return $String EndFunc
GEOSoft Posted March 29, 2009 Posted March 29, 2009 Here's another one for you ; $iLen = 12 $sStr = "" Do $sHold = Chr(Random(48, 122, 1)) If StringRegExp($sHold, "(?i)[a-z0-9]") Then $sStr &= $sHold Until StringLen($sStr) = $iLen MsgBox(0, "Results", $sStr) ; If You want Just upper case then change $sHold = Chr(Random(48, 122, 1)) To $sHold = Chr(Random(48, 90, 1)) George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
cypher175 Posted March 29, 2009 Author Posted March 29, 2009 Func _Randomstring($length) $chars= StringSplit("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789","") $String = "" $i=0 Do If $length<=0 then ExitLoop $String &= $chars[Random(1,$chars[0])] $i += 1 Until $i = $length Return $String EndFunc is there anyway to tweek this code so that the first character is always a random letter..??
TerarinK Posted March 29, 2009 Posted March 29, 2009 (edited) Func _RandomString($iLen) Local $sStr = "" Do If StringLen($sStr) Then $sTemp = Chr(Random(48, 122, 1)) If StringRegExp($sTemp, "(?i)[a-z0-9]") Then $sStr &= $sTemp Else $sTemp = Chr(Random(65, 122, 1)) If StringRegExp($sTemp, "(?i)[a-z]") Then $sStr &= $sTemp EndIf Until StringLen($sStr) = $iLen Return $sStr EndFunc ;==>_RandomString For a character ascii table there are many out there. Re-edited to show you the POINT in the exercise. Edited March 29, 2009 by TerarinK 0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E
Exit Posted March 29, 2009 Posted March 29, 2009 (edited) is there anyway to tweek this code so that the first character is always a random letter..??The previous post returns a NUMBER as first char. Here is a solution with the requested LETTER in the first position. ;-) Edit: previous post has been corrected. Func _RandomString($iLength) $aChars = StringSplit("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", "") $sString = "" While $iLength > StringLen($sString) If $sString < "A" Then $sString = "" $sString &= $aChars[Random(1, $aChars[0],1)] WEnd Return $sString EndFunc ;==>_RandomString MsgBox(0, '', _RandomString(10)) Edited March 30, 2009 by forumer100 App: Au3toCmd UDF: _SingleScript()
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