std::rand: Add an implementation of ISAAC64.

This is 2x faster on 64-bit computers at generating anything larger
than 32-bits.

It has been verified against the canonical C implementation from the
website of the creator of ISAAC64.

Also, move `Rng.next` to `Rng.next_u32` and add `Rng.next_u64` to
take full advantage of the wider word width; otherwise Isaac64 will
always be squeezed down into a u32 wasting half the entropy and
offering no advantage over the 32-bit variant.
This commit is contained in:
Huon Wilson 2013-09-21 22:06:50 +10:00
parent 72bf201d61
commit a2b509656a
8 changed files with 295 additions and 64 deletions

View file

@ -109,7 +109,7 @@ fn main() {
let mut rng = std::rand::IsaacRng::new_seeded([1, 1, 1, 1, 1, 1, 1]);
let mut set = HashSet::new();
while set.len() != n_keys {
let next = rng.next() as uint;
let next = rng.gen();
if set.insert(next) {
rand.push(next);
}

View file

@ -60,7 +60,7 @@ impl Results {
let mut set = f();
do timed(&mut self.random_ints) {
for _ in range(0, num_keys) {
set.insert((rng.next() as uint) % rand_cap);
set.insert(rng.gen::<uint>() % rand_cap);
}
}
}
@ -102,7 +102,7 @@ impl Results {
let mut set = f();
do timed(&mut self.random_strings) {
for _ in range(0, num_keys) {
let s = (rng.next() as uint).to_str();
let s = rng.gen::<uint>().to_str();
set.insert(s);
}
}

View file

@ -76,7 +76,7 @@ fn make_random_fasta(wr: @io::Writer,
wr.write_line(~">" + id + " " + desc);
let mut rng = rand::rng();
let rng = @mut MyRandom {
last: rng.next()
last: rng.gen()
};
let mut op: ~str = ~"";
for _ in range(0u, n as uint) {

View file

@ -69,8 +69,8 @@ pub fn main() {
let mut rng = rand::rng();
for f in fns.iter() {
let f = *f;
let sz = rng.next() % 256u32 + 256u32;
let frame_backoff = rng.next() % 10u32 + 1u32;
let sz = rng.gen::<u32>() % 256u32 + 256u32;
let frame_backoff = rng.gen::<u32>() % 10u32 + 1u32;
task::try(|| runtest(f, frame_backoff) );
}
}