Created
September 19, 2013 01:06
-
-
Save zippy/6617909 to your computer and use it in GitHub Desktop.
Failed attempt to add shuffle to Rust vec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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