Jump to content

Recommended Posts

Well I wrote this kinda quick. It works, but doesn't use every character in the original string, and sometimes repeats a character already used..

$sString = "07366024802gntlwcqybjf"
$aString = StringSplit($sString, "")
ConsoleWrite($sString & @LF)
For $c = 1 to $aString[0]
    ConsoleWrite($aString[Random(1, $aString[0], 1)])
Next
ConsoleWrite(@LF)

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Link to post
Share on other sites

Here is another way, same concept though :)

#include <Array.au3>

;_StringShuffle by smartee
Func _StringShuffle($sString, $iRepetitions=-1)
    Local $iA, $iB, $cTmp
    Local $aCharArray = StringSplit($sString, "", 1)
    If $iRepetitions=-1 Then $iRepetitions=$aCharArray[0]
    For $i = 1 To $iRepetitions
        $iA = Random(1, $aCharArray[0], 1)
        $iB = Random(1, $aCharArray[0], 1)
        $cTmp = $aCharArray[$iA]
        $aCharArray[$iA] = $aCharArray[$iB]
        $aCharArray[$iB] = $cTmp
    Next
    Return _ArrayToString($aCharArray,"",1)
EndFunc   ;==>_StringShuffle

MsgBox(64,"_StringShuffle",_StringShuffle("Hello World"))

EDIT: code typo with repetition 4 times ;)

Edited by smartee
Link to post
Share on other sites

And another way to skin the cat...

MsgBox(1, "", scramble("1234567890"))

;----------------------------------------------------------------
Func scramble($str)
Local $work = StringSplit($str, ""), $out = ""
For $max = $work[0] to 2 Step -1
    $rnd = Random(1, $max, 1)
    $out &= $work[$rnd]
    $work[$rnd] = $work[$max]
Next
Return $out & $work[1]
EndFunc
Edited by Spiff59
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...