Skip to main content
Changed to use a single RegEx statement. Thanks to @VasiliSyrakis.
Source Link
Iszi
  • 2.5k
  • 24
  • 26

PowerShell: 135119

Someone who understands RegEx better than I might be able to help trim this a bit.

Gofled Code

for(;!($x-cmatch'[acmatch'.*(?=.*[a-z]'z])+($x-cmatch'[A?=.*[A-Z]'Z])+($x-match'\d'?=.*\d)+($x-match'[?=.*[!-/:-@\[@[-`{-~]'~])-ne4.*')){$x='';1..15|%{$x+=[char](33..126|random)}}$x

Un-golfed and Commented

# Start a for loop definition.
for(
    # Skip variable initialization, start definition of run condition.
    ;(
        # CheckLoop runs if $x has a lowercase character.
        $x-cmatch'[a-z]'
does not meet complexity )+(requirements.
        # Check if $x has an uppercaseLength character.
requirement is not tested here because it is $x-cmatch'[A-Z]'
enforced by the generator )+(later.
      # Much #thanks Checkto if@VasiliSyrakis $xfor hasthe aRegEx numberhelp.
        !($x-match'\d'
    cmatch'.*(?=.*[a-z])+(
        # Check if $x has one of the required symbols?=.
        $x*[A-match'[Z])(?=.*\d)(?=.*[!-/:-@\[@[-`{-~]'
    # Run the script block if $x does not have all 4 character types included~]).
    *')-ne4
)
{
    # Reset $x in case the script block has already run.
    $x='';
    # Use ForEach-Object, via the % alias, to run a loop 15 times.
    1..15|%{
        # Append a random ASCII character from 33-126 to $x.
        # Note: Use get-random instead of random for faster performance.
        $x+=[char](33..126|random)
    }
}
# Display $x.
$x
# Variable cleanup - not included in golfed code.
rv x

PowerShell: 135

Someone who understands RegEx better than I might be able to help trim this a bit.

Gofled Code

for(;($x-cmatch'[a-z]')+($x-cmatch'[A-Z]')+($x-match'\d')+($x-match'[!-/:-@\[-`{-~]')-ne4){$x='';1..15|%{$x+=[char](33..126|random)}}$x

Un-golfed and Commented

# Start a for loop.
for(
    # Skip variable initialization, start definition of run condition.
    ;(
        # Check if $x has a lowercase character.
        $x-cmatch'[a-z]'
    )+(
        # Check if $x has an uppercase character.
        $x-cmatch'[A-Z]'
    )+(
        # Check if $x has a number.
        $x-match'\d'
    )+(
        # Check if $x has one of the required symbols.
        $x-match'[!-/:-@\[-`{-~]'
    # Run the script block if $x does not have all 4 character types included.
    )-ne4
)
{
    # Reset $x in case the script block has already run.
    $x='';
    # Use ForEach-Object, via the % alias, to run a loop 15 times.
    1..15|%{
        # Append a random ASCII character from 33-126 to $x.
        $x+=[char](33..126|random)
    }
}
# Display $x.
$x
# Variable cleanup - not included in golfed code.
rv x

PowerShell: 119

Gofled Code

for(;!($x-cmatch'.*(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!-/:-@[-`{-~]).*')){$x='';1..15|%{$x+=[char](33..126|random)}}$x

Un-golfed and Commented

# Start for loop definition.
for(
    # Skip variable initialization, start definition of run condition.
    ;
    # Loop runs if $x does not meet complexity requirements.
    # Length requirement is not tested here because it is enforced by the generator later.
    # Much thanks to @VasiliSyrakis for the RegEx help.
    !($x-cmatch'.*(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!-/:-@[-`{-~]).*')
)
{
    # Reset $x in case the script block has already run.
    $x='';
    # Use ForEach-Object, via the % alias, to run a loop 15 times.
    1..15|%{
        # Append a random ASCII character from 33-126 to $x.
        # Note: Use get-random instead of random for faster performance.
        $x+=[char](33..126|random)
    }
}
# Display $x.
$x
# Variable cleanup - not included in golfed code.
rv x
Removed space from the character pool.
Source Link
Iszi
  • 2.5k
  • 24
  • 26

PowerShell: 135

Someone who understands RegEx better than I might be able to help trim this a bit.

Gofled Code

for(;($x-cmatch'[a-z]')+($x-cmatch'[A-Z]')+($x-match'\d')+($x-match'[!-/:-@\[-`{-~]')-ne4){$x='';1..15|%{$x+=[char](3233..126|random)}}$x

Un-golfed and Commented

# Start a for loop.
for(
    # Skip variable initialization, start definition of run condition.
    ;(
        # Check if $x has a lowercase character.
        $x-cmatch'[a-z]'
    )+(
        # Check if $x has an uppercase character.
        $x-cmatch'[A-Z]'
    )+(
        # Check if $x has a number.
        $x-match'\d'
    )+(
        # Check if $x has one of the required symbols.
        $x-match'[!-/:-@\[-`{-~]'
    # Run the script block if $x does not have all 4 character types included.
    )-ne4
)
{
    # Reset $x in case the script block has already run.
    $x='';
    # Use ForEach-Object, via the % alias, to run a loop 15 times.
    1..15|%{
        # Append a random ASCII character from 3233-126 to $x.
        $x+=[char](3233..126|random)
    }
}
# Display $x.
$x
# Variable cleanup - not included in golfed code.
rv x

PowerShell: 135

Someone who understands RegEx better than I might be able to help trim this a bit.

Gofled Code

for(;($x-cmatch'[a-z]')+($x-cmatch'[A-Z]')+($x-match'\d')+($x-match'[!-/:-@\[-`{-~]')-ne4){$x='';1..15|%{$x+=[char](32..126|random)}}$x

Un-golfed and Commented

# Start a for loop.
for(
    # Skip variable initialization, start definition of run condition.
    ;(
        # Check if $x has a lowercase character.
        $x-cmatch'[a-z]'
    )+(
        # Check if $x has an uppercase character.
        $x-cmatch'[A-Z]'
    )+(
        # Check if $x has a number.
        $x-match'\d'
    )+(
        # Check if $x has one of the required symbols.
        $x-match'[!-/:-@\[-`{-~]'
    # Run the script block if $x does not have all 4 character types included.
    )-ne4
)
{
    # Reset $x in case the script block has already run.
    $x='';
    # Use ForEach-Object, via the % alias, to run a loop 15 times.
    1..15|%{
        # Append a random ASCII character from 32-126 to $x.
        $x+=[char](32..126|random)
    }
}
# Display $x.
$x
# Variable cleanup - not included in golfed code.
rv x

PowerShell: 135

Someone who understands RegEx better than I might be able to help trim this a bit.

Gofled Code

for(;($x-cmatch'[a-z]')+($x-cmatch'[A-Z]')+($x-match'\d')+($x-match'[!-/:-@\[-`{-~]')-ne4){$x='';1..15|%{$x+=[char](33..126|random)}}$x

Un-golfed and Commented

# Start a for loop.
for(
    # Skip variable initialization, start definition of run condition.
    ;(
        # Check if $x has a lowercase character.
        $x-cmatch'[a-z]'
    )+(
        # Check if $x has an uppercase character.
        $x-cmatch'[A-Z]'
    )+(
        # Check if $x has a number.
        $x-match'\d'
    )+(
        # Check if $x has one of the required symbols.
        $x-match'[!-/:-@\[-`{-~]'
    # Run the script block if $x does not have all 4 character types included.
    )-ne4
)
{
    # Reset $x in case the script block has already run.
    $x='';
    # Use ForEach-Object, via the % alias, to run a loop 15 times.
    1..15|%{
        # Append a random ASCII character from 33-126 to $x.
        $x+=[char](33..126|random)
    }
}
# Display $x.
$x
# Variable cleanup - not included in golfed code.
rv x
Source Link
Iszi
  • 2.5k
  • 24
  • 26

PowerShell: 135

Someone who understands RegEx better than I might be able to help trim this a bit.

Gofled Code

for(;($x-cmatch'[a-z]')+($x-cmatch'[A-Z]')+($x-match'\d')+($x-match'[!-/:-@\[-`{-~]')-ne4){$x='';1..15|%{$x+=[char](32..126|random)}}$x

Un-golfed and Commented

# Start a for loop.
for(
    # Skip variable initialization, start definition of run condition.
    ;(
        # Check if $x has a lowercase character.
        $x-cmatch'[a-z]'
    )+(
        # Check if $x has an uppercase character.
        $x-cmatch'[A-Z]'
    )+(
        # Check if $x has a number.
        $x-match'\d'
    )+(
        # Check if $x has one of the required symbols.
        $x-match'[!-/:-@\[-`{-~]'
    # Run the script block if $x does not have all 4 character types included.
    )-ne4
)
{
    # Reset $x in case the script block has already run.
    $x='';
    # Use ForEach-Object, via the % alias, to run a loop 15 times.
    1..15|%{
        # Append a random ASCII character from 32-126 to $x.
        $x+=[char](32..126|random)
    }
}
# Display $x.
$x
# Variable cleanup - not included in golfed code.
rv x