auto merge of #8558 : kballard/rust/xorshift-seed, r=cmr

Fixes #8359.
This commit is contained in:
bors 2013-08-18 10:01:55 -07:00
commit 88bd2155d7

View File

@ -875,13 +875,22 @@ impl Rng for XorShiftRng {
}
impl XorShiftRng {
/// Create an xor shift random number generator with a default seed.
/// Create an xor shift random number generator with a random seed.
pub fn new() -> XorShiftRng {
// constants taken from http://en.wikipedia.org/wiki/Xorshift
XorShiftRng::new_seeded(123456789u32,
362436069u32,
521288629u32,
88675123u32)
// generate seeds the same way as seed(), except we have a spceific size
let mut s = [0u8, ..16];
loop {
do s.as_mut_buf |p, sz| {
unsafe {
rustrt::rand_gen_seed(p, sz as size_t);
}
}
if !s.iter().all(|x| *x == 0) {
break;
}
}
let s: &[u32, ..4] = unsafe { cast::transmute(&s) };
XorShiftRng::new_seeded(s[0], s[1], s[2], s[3])
}
/**