File tree 1 file changed +15
-6
lines changed
1 file changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -875,13 +875,22 @@ impl Rng for XorShiftRng {
875
875
}
876
876
877
877
impl XorShiftRng {
878
- /// Create an xor shift random number generator with a default seed.
878
+ /// Create an xor shift random number generator with a random seed.
879
879
pub fn new ( ) -> XorShiftRng {
880
- // constants taken from http://en.wikipedia.org/wiki/Xorshift
881
- XorShiftRng :: new_seeded ( 123456789u32 ,
882
- 362436069u32 ,
883
- 521288629u32 ,
884
- 88675123u32 )
880
+ // generate seeds the same way as seed(), except we have a spceific size
881
+ let mut s = [ 0u8 , ..16 ] ;
882
+ loop {
883
+ do s. as_mut_buf |p, sz| {
884
+ unsafe {
885
+ rustrt:: rand_gen_seed ( p, sz as size_t ) ;
886
+ }
887
+ }
888
+ if !s. iter ( ) . all ( |x| * x == 0 ) {
889
+ break ;
890
+ }
891
+ }
892
+ let s: & [ u32 , ..4 ] = unsafe { cast:: transmute ( & s) } ;
893
+ XorShiftRng :: new_seeded ( s[ 0 ] , s[ 1 ] , s[ 2 ] , s[ 3 ] )
885
894
}
886
895
887
896
/**
You can’t perform that action at this time.
0 commit comments