Search code examples
arrayspowershellnumbers

Get two random separate numbers?


For Get-Random, how would it be possible to get random numbers and having the results looking like this?

'100,100'

Solution

  • Using the -Count parameter is what you are after. Unfortunately you will need to provide it with the min/max via the Pipeline.

    # String
    (1..100 | Get-Random -Count 2) -join ',' 
    # Array
    1..100 | Get-Random -Count 2 
    

    More details about Get-Random can be found on the MS Page.