Skip to content

Commit f945e34

Browse files
committed
remove unneeded dependency on rand
1 parent 915aa22 commit f945e34

File tree

4 files changed

+20
-21
lines changed

4 files changed

+20
-21
lines changed

benchmark/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,4 @@ path = "run_all.rs"
1919
capnpc = { path = "../capnpc" }
2020

2121
[dependencies]
22-
rand = "0.4"
2322
capnp = { path = "../capnp" }

benchmark/benchmark.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
// THE SOFTWARE.
2121

2222
extern crate capnp;
23-
extern crate rand;
2423

2524
use std::{mem, io};
2625

benchmark/carsales.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2020
// THE SOFTWARE.
2121

22-
use rand::*;
2322
use common::*;
2423
use carsales_capnp::{parking_lot, total_value, Color, car};
2524

@@ -114,17 +113,17 @@ pub fn random_car(rng: &mut FastRand, mut car: car::Builder) {
114113
engine.set_cylinders(4 + 2 * rng.next_less_than(3) as u8);
115114
engine.set_cc(800 + rng.next_less_than(10000));
116115
engine.set_uses_gas(true);
117-
engine.set_uses_electric(rng.gen());
116+
engine.set_uses_electric(rng.next_bool());
118117
}
119118

120119
let fuel_capacity = (10.0 + rng.next_double(30.0)) as f32;
121120
car.set_fuel_capacity(fuel_capacity);
122121
car.set_fuel_level(rng.next_double(fuel_capacity as f64) as f32);
123-
car.set_has_power_windows(rng.gen());
124-
car.set_has_power_steering(rng.gen());
125-
car.set_has_cruise_control(rng.gen());
122+
car.set_has_power_windows(rng.next_bool());
123+
car.set_has_power_steering(rng.next_bool());
124+
car.set_has_cruise_control(rng.next_bool());
126125
car.set_cup_holders(rng.next_less_than(12) as u8);
127-
car.set_has_nav_system(rng.gen());
126+
car.set_has_nav_system(rng.next_bool());
128127
}
129128

130129
pub struct CarSales;

benchmark/common.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2020
// THE SOFTWARE.
2121

22-
use rand::*;
2322
use std::i32;
2423

2524
#[derive(Clone, Copy)]
@@ -30,18 +29,6 @@ pub struct FastRand {
3029
w: u32,
3130
}
3231

33-
impl Rng for FastRand {
34-
#[inline]
35-
fn next_u32(&mut self) -> u32 {
36-
let tmp = self.x ^ (self.x << 11);
37-
self.x = self.y;
38-
self.y = self.z;
39-
self.z = self.w;
40-
self.w = self.w ^ (self.w >> 19) ^ tmp ^ (tmp >> 8);
41-
return self.w;
42-
}
43-
}
44-
4532
impl FastRand {
4633
pub fn new() -> FastRand {
4734
FastRand {
@@ -52,11 +39,26 @@ impl FastRand {
5239
}
5340
}
5441

42+
#[inline]
43+
pub fn next_u32(&mut self) -> u32 {
44+
let tmp = self.x ^ (self.x << 11);
45+
self.x = self.y;
46+
self.y = self.z;
47+
self.z = self.w;
48+
self.w = self.w ^ (self.w >> 19) ^ tmp ^ (tmp >> 8);
49+
return self.w;
50+
}
51+
5552
#[inline]
5653
pub fn next_less_than(&mut self, range : u32) -> u32 {
5754
self.next_u32() % range
5855
}
5956

57+
#[inline]
58+
pub fn next_bool(&mut self) -> bool {
59+
(self.next_u32() % 2) == 1
60+
}
61+
6062
#[inline]
6163
pub fn next_double(&mut self, range : f64) -> f64 {
6264
use std::u32;

0 commit comments

Comments
 (0)