Jump to content

Randomizing Names?


Recommended Posts

Would it be possible to create a script that, when given the letters and numbers could randomize them multiple times, remember the choice and type it out?

Say... i give it the letters

ASDF

Could it create

ADSF

SDAF

FASD

without repeating itself?

Edited by bobert
Link to comment
Share on other sites

Of course this is possible...

I think of a method you create an array with all possibilities in it and you display a random number in that display. Depending on the needs you delete the output array from the array or put the chosen number in a variable.

In the beginning there was nothing and then even that exploded - anonymous

Link to comment
Share on other sites

$Names = "ASDF"

;---------------------------
$tries = 500
Dim $List = "", $counter
$Split = StringSplit($Names, "")
$count = $Split[0]

For $x = 1 To $tries
    $nName = ""
    For $i = 1 To $Split[0]
        $nName &= $Split[Random(1, $count, 1)]
    Next
    If StringInStr($List, $nName) Then ContinueLoop
    $List &= $nName & @CRLF
    $x = 0
    $counter += 1
    Sleep(1)
Next

MsgBox(0x0, $counter, $List)

8)

UPDATED. able to use any length set now

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

With this, you can watch it work..

$Names = "12345"

;---------------------------
$tries = 500
Dim $List = "", $counter, $Tcount
$Split = StringSplit($Names, "")
$count = $Split[0]

For $x = 1 To $tries
    $nName = ""
    For $i = 1 To $Split[0]
        $nName &= $Split[Random(1, $count, 1)]
    Next
    $Tcount +=1
    If StringInStr($List, $nName) Then ContinueLoop
    $List &= $nName & @CRLF
    $x = 0
    $counter += 1
    ToolTip( "Total Tries = " &$Tcount & @CRLF & "Difference = " &$Tcount - $counter, 10, 10, "Actual = " &$counter, 1)
    Sleep(1)
Next

MsgBox(0x0, $counter, $List)

8)

NEWHeader1.png

Link to comment
Share on other sites

[b]$permutarray = permute("123456")
$msg = ""
For $n = 1 To $permutarray[0]
    $msg &= $permutarray[$n] & @CRLF
Next
ConsoleWrite($msg)

Func rotate($sString, $nRotateLevel)
    Local $aStringArray = StringSplit($sString, "")
    Local $nStartRotate = $aStringArray[0] - $nRotateLevel + 1
    Local $n, $tempchar, $tempstr = "", $retval = ""
    For $n = 1 To $nStartRotate - 1
        $tempstr &= $aStringArray[$n]
    Next
    $tempchar = $aStringArray[$nStartRotate]
    For $n = $nStartRotate + 1 To $aStringArray[0]
        $retval &= $aStringArray[$n]
    Next
    Return $tempstr & $retval & $tempchar
EndFunc  ;==>rotate

Func permute_internal($sString, $nRotateLevel, ByRef $permutations)
    Local $n, $str
    Dim $arr[$nRotateLevel]
    If $nRotateLevel = 2 Then
        $permutations &= ":" & rotate($sString, $nRotateLevel)
        Return
    EndIf
    $str = $sString
    For $n = 0 To $nRotateLevel - 1
        $str = rotate($str, $nRotateLevel)
        $arr[$n] = $str
       ;--- special check, to stop a level beeing printed twice ---
        If Not (($n = 0) And (StringLen($sString) > $nRotateLevel)) Then
            $permutations &= ":" & $arr[$n]
        EndIf
        permute_internal($arr[$n], $nRotateLevel - 1, $permutations)
    Next
EndFunc  ;==>permute_internal

Func permute($sString)
    Global $permutations = ""
    permute_internal($sString, StringLen($sString), $permutations)
    $permutations = StringTrimLeft($permutations, 1)
    Return StringSplit($permutations, ":")
EndFunc  ;==>permute[/b]

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...