13
13
use std:: cell:: RefCell ;
14
14
use std:: rc:: Rc ;
15
15
16
- use { RngCore , CryptoRng , StdRng , SeedableRng , EntropyRng } ;
17
- use { Distribution , Uniform , Rng , Error } ;
16
+ use { RngCore , CryptoRng , StdRng , SeedableRng , EntropyRng , Error } ;
18
17
use reseeding:: ReseedingRng ;
19
18
20
19
// Number of generated bytes after which to reseed `TreadRng`.
@@ -99,57 +98,9 @@ impl RngCore for ThreadRng {
99
98
100
99
impl CryptoRng for ThreadRng { }
101
100
102
- /// Generates a random value using the thread-local random number generator.
103
- ///
104
- /// This is simply a shortcut for `thread_rng().gen()`. See [`thread_rng`] for
105
- /// documentation of the entropy source and [`Rand`] for documentation of
106
- /// distributions and type-specific generation.
107
- ///
108
- /// # Examples
109
- ///
110
- /// ```
111
- /// let x = rand::random::<u8>();
112
- /// println!("{}", x);
113
- ///
114
- /// let y = rand::random::<f64>();
115
- /// println!("{}", y);
116
- ///
117
- /// if rand::random() { // generates a boolean
118
- /// println!("Better lucky than good!");
119
- /// }
120
- /// ```
121
- ///
122
- /// If you're calling `random()` in a loop, caching the generator as in the
123
- /// following example can increase performance.
124
- ///
125
- /// ```
126
- /// use rand::Rng;
127
- ///
128
- /// let mut v = vec![1, 2, 3];
129
- ///
130
- /// for x in v.iter_mut() {
131
- /// *x = rand::random()
132
- /// }
133
- ///
134
- /// // can be made faster by caching thread_rng
135
- ///
136
- /// let mut rng = rand::thread_rng();
137
- ///
138
- /// for x in v.iter_mut() {
139
- /// *x = rng.gen();
140
- /// }
141
- /// ```
142
- ///
143
- /// [`thread_rng`]: fn.thread_rng.html
144
- /// [`Rand`]: trait.Rand.html
145
- #[ inline]
146
- pub fn random < T > ( ) -> T where Uniform : Distribution < T > {
147
- thread_rng ( ) . gen ( )
148
- }
149
-
150
101
#[ cfg( test) ]
151
102
mod test {
152
- use super :: * ;
103
+ use Rng ;
153
104
154
105
#[ test]
155
106
#[ cfg( feature="std" ) ]
@@ -163,18 +114,4 @@ mod test {
163
114
assert_eq ! ( v, b) ;
164
115
assert_eq ! ( r. gen_range( 0 , 1 ) , 0 ) ;
165
116
}
166
-
167
- #[ test]
168
- fn test_random ( ) {
169
- // not sure how to test this aside from just getting some values
170
- let _n : usize = random ( ) ;
171
- let _f : f32 = random ( ) ;
172
- let _o : Option < Option < i8 > > = random ( ) ;
173
- let _many : ( ( ) ,
174
- ( usize ,
175
- isize ,
176
- Option < ( u32 , ( bool , ) ) > ) ,
177
- ( u8 , i8 , u16 , i16 , u32 , i32 , u64 , i64 ) ,
178
- ( f32 , ( f64 , ( f64 , ) ) ) ) = random ( ) ;
179
- }
180
117
}
0 commit comments