[AutoIt]Pseudorandom String Generator
#1
The function:
Code:
Func _pGenerate($sLen)
   Local $aCharset = StringSplit("0123456789!@#$%^&*-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", "")
   Local $sRand = 0, $sDupCheck = 0, $sReturn = ""

   For $i = 1 to $sLen
      $sRand = Round(Random(1, $aCharset[0], 1))
      if $sRand < ($sDupCheck - 4) OR $sRand > ($sDupCheck + 4) Then
         $sReturn &= $aCharset[$sRand]
         $sDupCheck = $sRand
      Else
         $i -= 1
      EndIf
   Next

   Return $sReturn
EndFunc ;==> _pGenerate()

Usage:
Code:
Local $length = InputBox("Length", "How many characters?")
ClipPut(_pGenerate($length))
MsgBox(64, "Results", "Added the new string to the clipboard")

Entropy is obviously not a major concern here, but this comes in handy.
Reply
#2
AutoIT looks very cumbersome and inefficient compared to Python, but then again i am probably biased. Anyway generating a pseudorandom string with python would look like this.

Code:
import random, string

def string_generator(length=10):
   return ''.join(random.choice(string.lowercase) for _ in range(length))

Calling the function we just defined from the interpreter results in the following.

Code:
>>> string_generator(10)
'yaiemstwrv'

I suppose if we want uppercase letters, lowercase letters and digits the function might look a little like this.

Code:
import random, string

def string_generator(length=10,chars=string.ascii_uppercase + string.ascii_lowercase + string.digits):
    return ''.join(random.choice(chars) for _ in range(length)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [AutoIt][EXE]Auto Proxy b1nary 1 11,733 03-13-2016, 01:23 PM
Last Post: Vector
  [AutoIt]ASCII to Morse Code b1nary 4 17,557 01-29-2016, 06:45 PM
Last Post: b1nary