|
10 | 10 |
|
11 | 11 | //! The ISAAC random number generator.
|
12 | 12 |
|
13 |
| -use cast; |
14 | 13 | use rand::{Rng, SeedableRng, OSRng};
|
15 | 14 | use iter::{Iterator, range, range_step, Repeat};
|
16 | 15 | use option::{None, Some};
|
| 16 | +use vec::raw; |
| 17 | +use mem; |
17 | 18 |
|
18 | 19 | static RAND_SIZE_LEN: u32 = 8;
|
19 | 20 | static RAND_SIZE: u32 = 1 << RAND_SIZE_LEN;
|
@@ -42,9 +43,12 @@ impl IsaacRng {
|
42 | 43 | pub fn new() -> IsaacRng {
|
43 | 44 | let mut rng = EMPTY;
|
44 | 45 |
|
45 |
| - { |
46 |
| - let bytes = unsafe {cast::transmute::<&mut [u32], &mut [u8]>(rng.rsl)}; |
47 |
| - OSRng::new().fill_bytes(bytes); |
| 46 | + unsafe { |
| 47 | + let ptr = raw::to_mut_ptr(rng.rsl); |
| 48 | + |
| 49 | + do raw::mut_buf_as_slice(ptr as *mut u8, mem::size_of_val(&rng.rsl)) |slice| { |
| 50 | + OSRng::new().fill_bytes(slice); |
| 51 | + } |
48 | 52 | }
|
49 | 53 |
|
50 | 54 | rng.init(true);
|
@@ -238,10 +242,15 @@ impl Isaac64Rng {
|
238 | 242 | /// seed.
|
239 | 243 | pub fn new() -> Isaac64Rng {
|
240 | 244 | let mut rng = EMPTY_64;
|
241 |
| - { |
242 |
| - let bytes = unsafe {cast::transmute::<&mut [u64], &mut [u8]>(rng.rsl)}; |
243 |
| - OSRng::new().fill_bytes(bytes); |
| 245 | + |
| 246 | + unsafe { |
| 247 | + let ptr = raw::to_mut_ptr(rng.rsl); |
| 248 | + |
| 249 | + do raw::mut_buf_as_slice(ptr as *mut u8, mem::size_of_val(&rng.rsl)) |slice| { |
| 250 | + OSRng::new().fill_bytes(slice); |
| 251 | + } |
244 | 252 | }
|
| 253 | + |
245 | 254 | rng.init(true);
|
246 | 255 | rng
|
247 | 256 | }
|
|
0 commit comments