Jump to content

Same Random() values across PC's

Recommended Posts


I've this script (removed unrelated parts) that generate a set of random chars for a password. It gets launched from a network share by Task Scheduler at a specific time for all PC's, then it relaunches itself from the local drive.


Global $LocalToolsDir = @ProgramFilesDir & '\Tools'


Func Start()
    If Not StringInStr(@ScriptFullPath, $LocalToolsDir, 2) Then Exit RunLocaly()

    Sleep(Random(1, 1800, 1) * 1000)

    $NewPass = GeneratePass()

Func GeneratePass()
    Local $Pass
    For $i = 1 to 8
        $R = Random(0,1.5)

        If $R > 1 Then
            $Chr = Random(0,9,1)
        ElseIf $R < 0.5 Then
            $Chr = Chr(Random(Asc("A"), Asc("Z"), 1))
            $Chr = Chr(Random(Asc("a"), Asc("z"), 1))
        $Pass &= $Chr
    Return $Pass

Func RunLocaly()
    Local $Run = 1, $LocalApp = $LocalToolsDir & '\' & @ScriptName

    If Not FileExists($LocalApp) Then $Run = FileCopy(@ScriptFullPath, $LocalToolsDir, 1 + 8)
    If $Run Then Run($LocalApp, $LocalToolsDir)


The problem is that many PC's ends up with the same password(s).
e.g. 10 PC's have (abc123) as a Password, and another 10 have this (def456)

Any idea why?

Link to comment
Share on other sites

Add SRandom(@AutoItPID) at the top of your script and your issue will magically disappear.;)

Edited by RTFC
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

  • Create New...