Skip to content

Instantly share code, notes, and snippets.

@zippy
Created September 19, 2013 01:06
Show Gist options
  • Save zippy/6617909 to your computer and use it in GitHub Desktop.
Save zippy/6617909 to your computer and use it in GitHub Desktop.
Failed attempt to add shuffle to Rust vec
pub trait MutableVector<'self, T> {
fn shuffle(self);
}
impl<'self, T> MutableVector<'self, T> for &'self mut [T] {
fn shuffle(self) {
let l=self.len();
let mut i=l;
let mut rng = rand::rng();
loop {
if i==0 {break;}
self.swap(i-1,rng.gen_uint_range(0,l));
i = i -1;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment