Skip to main content
deleted 11 characters in body
Source Link
lyxal
  • 34.3k
  • 2
  • 64
  • 141

Vyxal, 1413 bytes

:ẏÞS℅~İṖ℅Z(n÷Ȧ

Try it Online!Try it Online!

Explained

:ẏÞS℅~İṖ℅Z(n÷Ȧ
:ẏ             # Push the input and the range [0, len(input))
  ÞS℅          # Choose a random sublist of indices
     ~İ        # And index into the input at those places, without popping anything
       Ṗ℅      # Choose a random permutation of the indexed items
         Z     # and zip that with the chosen indices - this creates a list of [[original index, new item]...]
          (    # for each pair:
           n÷Ȧ # input[original index] = new item
 

Vyxal, 14 bytes

:ẏÞS℅~İṖ℅Z(n÷Ȧ

Try it Online!

Explained

:ẏÞS℅~İṖ℅Z(n÷Ȧ
:ẏ             # Push the input and the range [0, len(input))
  ÞS℅          # Choose a random sublist of indices
     ~İ        # And index into the input at those places, without popping anything
       Ṗ℅      # Choose a random permutation of the indexed items
         Z     # and zip that with the chosen indices - this creates a list of [[original index, new item]...]
          (    # for each pair:
           n÷Ȧ # input[original index] = new item
 

Vyxal, 13 bytes

ẏÞS℅~İṖ℅Z(n÷Ȧ

Try it Online!

Explained

ẏÞS℅~İṖ℅Z(n÷Ȧ
ẏ             # Push the input and the range [0, len(input))
 ÞS℅          # Choose a random sublist of indices
    ~İ        # And index into the input at those places, without popping anything
      Ṗ℅      # Choose a random permutation of the indexed items
        Z     # and zip that with the chosen indices - this creates a list of [[original index, new item]...]
         (    # for each pair:
          n÷Ȧ # input[original index] = new item
Source Link
lyxal
  • 34.3k
  • 2
  • 64
  • 141

Vyxal, 14 bytes

:ẏÞS℅~İṖ℅Z(n÷Ȧ

Try it Online!

Explained

:ẏÞS℅~İṖ℅Z(n÷Ȧ
:ẏ             # Push the input and the range [0, len(input))
  ÞS℅          # Choose a random sublist of indices
     ~İ        # And index into the input at those places, without popping anything
       Ṗ℅      # Choose a random permutation of the indexed items
         Z     # and zip that with the chosen indices - this creates a list of [[original index, new item]...]
          (    # for each pair:
           n÷Ȧ # input[original index] = new item