Buchstaben

  • Hab mal vor einiger Zeit ne func geschrieben welche heisst _Random09az

    [autoit]

    ;===============================================================================
    ;
    ; Function Name: _random09az()
    ; Description: Returns a given number of signs, one sign can be a-z or 0-9 or A-Z
    ; Parameter(s): $iCount - Number of random signs ( standard = 1 )
    ; Requirement(s): None
    ; Return Value(s): On Success - Returns the random sign(s)
    ; On Failure - Returns -1 and sets @error
    ; Author(s): qon
    ;
    ;===============================================================================

    [/autoit][autoit][/autoit][autoit]

    func _random09az($iCount = 1)
    If Stringisdigit($iCount) = 0 Then
    Seterror(1)
    Return -1
    EndIf

    Local $sString = ""

    For $i = $iCount to 1 step -1
    Local $iRandom = Random(1,4,1)
    IF $iRandom = 1 Then
    $iRandom = Chr(Random(48,57,1))
    $sString = $sString & $iRandom
    ContinueLoop
    EndIf
    If $iRandom = 2 Or $iRandom = 3 then
    $iRandom = Chr(Random(97,122,1))
    $sString = $sString & $iRandom
    ContinueLoop
    EndIf
    IF $iRandom = 4 Then
    $iRandom = Chr(Random(65,90,1))
    $sString = $sString & $iRandom
    ContinueLoop
    EndIf
    Next

    Return $sString
    EndFunc

    [/autoit]
  • qon:
    versuch mal das, wesentlich kürzer.

    [autoit]

    ;===============================================================================
    ;
    ; Function Name: _random09az()
    ; Description: Returns a given number of signs, one sign can be a-z or 0-9 or A-Z
    ; Parameter(s): $iCount - Number of random signs ( standard = 1 )
    ; Requirement(s): None
    ; Return Value(s): On Success - Returns the random sign(s)
    ; On Failure - Returns -1 and sets @error
    ; Author(s): qon
    ;
    ;===============================================================================

    [/autoit][autoit][/autoit][autoit]

    Func _random09az($iCount = 1)
    If Not StringIsDigit($iCount) Then SetError(1, 0, -1)
    If $iCount = 0 Then SetError(2, 0, -1)

    Local $iRandom, $sRandom, $sString

    For $i = 1 To $iCount
    $iRandom = Random(1,4,1)
    If $iRandom = 1 Then $sRandom = Chr(Random(48,57,1))
    If $iRandom = 2 Or $iRandom = 3 Then $sRandom = Chr(Random(97,122,1))
    If $iRandom = 4 Then $sRandom = Chr(Random(65,90,1))
    $sString &= $sRandom
    Next

    Return $sString
    EndFunc

    [/autoit]

    2 Mal editiert, zuletzt von m-obi (20. März 2010 um 14:23)