Shuffle a string

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

  • Author
    Posts
  • #68641
    Profile photo of Mark Prior
    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
    Profile photo of Olaf Soyk
    Olaf Soyk
    Participant
    ($string -split '' | Sort-Object {Get-Random}) -join ''
  • #68646
    Profile photo of Mark Prior
    Mark Prior
    Participant

    Thanks Olaf

  • #68709
    Profile photo of Max Kozlov
    Max Kozlov
    Participant

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

You must be logged in to reply to this topic.