Shuffle a string

This topic contains 3 replies, has 3 voices, and was last updated by  Max Kozlov 4 months, 1 week ago.

  • Author
    Posts
  • #68641

    Mark Prior
    Participant

    Hopefully easy 🙂

    
    $string = "12345678"
    
    

    how do i shuffle said sting to produce a random arrangement ? i.e numbers come out as 153264987?

  • #68643

    Olaf Soyk
    Participant
    ($string -split '' | Sort-Object {Get-Random}) -join ''
  • #68646

    Mark Prior
    Participant

    Thanks Olaf

  • #68709

    Max Kozlov
    Participant

    oneliner contest ? 🙂
    ($string.ToCharArray() | Get-Random -Count $string.Length) -join "

You must be logged in to reply to this topic.