Skip to main content
deleted 4 characters in body
Source Link
Noodle9
  • 20.3k
  • 3
  • 21
  • 46

C++ (gcc), 197 \$\cdots\$ 182175 175174 bytes

#import<regex>
using V=std::vector<int>;voidvector<int>;int f(V&v){V i=v,r=v;int y=0,n,j;for(int&a:i)a=y++;std::random_shuffle(&i[0],&*end(i));for(j=n=rand()%y+1;j;)r[i[--j]]=v[i[j%n]];v=r;}

Try it online!Try it online!

Added 2 bytes to fix an error.
Saved 3 5 bytes thanks to ceilingcat!!!

Inputs a vector of integers.
Randomly shuffles a random subgroup of the elements in place.

C++ (gcc), 197 \$\cdots\$ 182 175 bytes

#import<regex>
using V=std::vector<int>;void f(V&v){V i=v,r=v;int y=0,n,j;for(int&a:i)a=y++;std::random_shuffle(&i[0],&*end(i));for(j=n=rand()%y+1;j;)r[i[--j]]=v[i[j%n]];v=r;}

Try it online!

Added 2 bytes to fix an error.
Saved 3 5 bytes thanks to ceilingcat!!!

Inputs a vector of integers.
Randomly shuffles a random subgroup of the elements in place.

C++ (gcc), 197 \$\cdots\$ 175 174 bytes

#import<regex>
using V=std::vector<int>;int f(V&v){V i=v,r=v;int y=0,n,j;for(int&a:i)a=y++;std::random_shuffle(&i[0],&*end(i));for(j=n=rand()%y+1;j;)r[i[--j]]=v[i[j%n]];v=r;}

Try it online!

Added 2 bytes to fix an error.
Saved 3 5 bytes thanks to ceilingcat!!!

Inputs a vector of integers.
Randomly shuffles a random subgroup of the elements in place.

deleted 9 characters in body
Source Link
Noodle9
  • 20.3k
  • 3
  • 21
  • 46

C++ (gcc), 197 \$\cdots\$ 184182 182175 bytes

#import<regex>
using V=std::vector<int>;void f(V&v){V i=v,r=v;int y=0,n,j;for(int&a:i)a=y++;std::random_shuffle(&i[0],&*end(i));for(j=n=rand()%v.size()+1;j;%y+1;j;)r[i[--j]]=v[i[j%n]];v=r;}

Try it online!Try it online!

Added 2 bytes to fix an error.
Saved 3 5 bytes thanks to ceilingcat!!!

Inputs a vector of integers.
Randomly shuffles a random subgroup of the elements in place.

C++ (gcc), 197 \$\cdots\$ 184 182 bytes

#import<regex>
using V=std::vector<int>;void f(V&v){V i=v,r=v;int y=0,n,j;for(int&a:i)a=y++;std::random_shuffle(&i[0],&*end(i));for(j=n=rand()%v.size()+1;j;)r[i[--j]]=v[i[j%n]];v=r;}

Try it online!

Added 2 bytes to fix an error.
Saved 3 5 bytes thanks to ceilingcat!!!

Inputs a vector of integers.
Randomly shuffles a random subgroup of the elements in place.

C++ (gcc), 197 \$\cdots\$ 182 175 bytes

#import<regex>
using V=std::vector<int>;void f(V&v){V i=v,r=v;int y=0,n,j;for(int&a:i)a=y++;std::random_shuffle(&i[0],&*end(i));for(j=n=rand()%y+1;j;)r[i[--j]]=v[i[j%n]];v=r;}

Try it online!

Added 2 bytes to fix an error.
Saved 3 5 bytes thanks to ceilingcat!!!

Inputs a vector of integers.
Randomly shuffles a random subgroup of the elements in place.

added 8 characters in body
Source Link
Noodle9
  • 20.3k
  • 3
  • 21
  • 46

C++ (gcc), 197 \$\cdots\$ 185184 184182 bytes

#import<regex>
using V=std::vector<int>;void f(V&v){V i=v,r=v;int y=0;fory=0,n,j;for(int&a:i)a=y++;std::random_shuffle(&i[0],&*end(i));for(int n=randj=n=rand()%v.size()+1,j=n;j;+1;j;)r[i[--j]]=v[i[j%n]];v=r;}

Try it online!Try it online!

Added 2 bytes to fix an error.
Saved 33 5 bytes thanks to ceilingcat!!!

Inputs a vector of integers.
Randomly shuffles a random subgroup of the elements in place.

C++ (gcc), 197 \$\cdots\$ 185 184 bytes

#import<regex>
using V=std::vector<int>;void f(V&v){V i=v,r=v;int y=0;for(int&a:i)a=y++;std::random_shuffle(&i[0],&*end(i));for(int n=rand()%v.size()+1,j=n;j;)r[i[--j]]=v[i[j%n]];v=r;}

Try it online!

Added 2 bytes to fix an error.
Saved 3 bytes thanks to ceilingcat!!!

Inputs a vector of integers.
Randomly shuffles a random subgroup of the elements in place.

C++ (gcc), 197 \$\cdots\$ 184 182 bytes

#import<regex>
using V=std::vector<int>;void f(V&v){V i=v,r=v;int y=0,n,j;for(int&a:i)a=y++;std::random_shuffle(&i[0],&*end(i));for(j=n=rand()%v.size()+1;j;)r[i[--j]]=v[i[j%n]];v=r;}

Try it online!

Added 2 bytes to fix an error.
Saved 3 5 bytes thanks to ceilingcat!!!

Inputs a vector of integers.
Randomly shuffles a random subgroup of the elements in place.

deleted 12 characters in body
Source Link
Noodle9
  • 20.3k
  • 3
  • 21
  • 46
Loading
deleted 2 characters in body
Source Link
Noodle9
  • 20.3k
  • 3
  • 21
  • 46
Loading
added 179 characters in body
Source Link
Noodle9
  • 20.3k
  • 3
  • 21
  • 46
Loading
Source Link
Noodle9
  • 20.3k
  • 3
  • 21
  • 46
Loading