locked
Like to generate random set of positive and negative numbers based on the input value RRS feed

  • Question

  • I would like to generate password for the remote system by changing the value of "$single_digit_count".  Our goal is - based on the day of the month, we would like to change the value of the "$single_digit_count" to generate admin password for remote machine.  

    Can someone please assist me to achieve my goal?  I would really appreciate your help.

    I have come up with the following:    

    # =============================

    # For the 10th day of the month.  Generate 10 random number including some negative numbers

    # For the 11th day of the month, we would like to generate 11 numbers including some negative numbers and so on...

    Function get-10s_with_minus{

    Param ($inputval)

    $single_digit_count = 10 
    $num1 = Get-Random -InputObject(1..9) -Count ($single_digit_count -8) # 2
    $num1

    $num2 = Get-Random -InputObject(-7..9) -Count ($single_digit_count - 9) # 1
    $num2

    $snum2 = ($num1 | measure -sum) | select Sum

    $n2 = $snum2.Sum

    $num3 = Get-Random -InputObject(1..9) -Count ($single_digit_count - 6) # 4
    $num3

    $num4 = Get-Random -InputObject(-$n2..$n2) -Count ($single_digit_count - 9) # 1
    $num4

    $num5 = Get-Random -InputObject(1..9) -Count ($single_digit_count - 8) # 2
    $num5

    # Adding all the random generated numbers
    $result = (($num1 + $num2 + $num3 + $num4 + $num5) | measure -sum) | select sum

    $sum10_wm = $result.sum

    $input_total = Read-Host "Total "

    if ($input_total -eq "quit".ToLower()){
        break 
        }

    if ($sum10_wm -eq $input_total){

    generate_password.ps1

        }
        else
        {

        Write-host "Your input did not match" -ForegroundColor Red

        }
    }

    $inputval = Read-Host "Enter value " 
    while (($input_total -ne "quit") -and ($inputval -eq 1)){

    get-10s_with_minus $inputval

    }


    • Edited by shapon7 Thursday, February 27, 2020 4:41 AM Generate secure password
    Thursday, February 27, 2020 4:36 AM

All replies