Jump to content
Sign in to follow this  
HeniutX

Mix string

Recommended Posts

HeniutX

I have

07366024802gntlwcqybjf

, And I want to do this for example:

0q3j60l4bn2g0t2wc7y86f

So, I mean the mixing of characters.

I apologize for mistakes. I come from a Polish

Share this post


Link to post
Share on other sites
somdcomputerguy

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.

Share this post


Link to post
Share on other sites
smartee

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

Share this post


Link to post
Share on other sites
Spiff59

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

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  

×