@@ -171,9 +171,9 @@ pub fn find_hash_factor_for_dictionary(tokens: impl IntoIterator<Item = Vec<u8>>
171171 use rand:: Rng ;
172172
173173 let all_tokens = tokens. into_iter ( ) . collect_vec ( ) ;
174- let mut rnd = rand:: thread_rng ( ) ;
174+ let mut rnd = rand:: rng ( ) ;
175175 loop {
176- let factor: u64 = rnd. gen ( ) ;
176+ let factor: u64 = rnd. random ( ) ;
177177 let mut seen = HashSet :: new ( ) ;
178178 if all_tokens
179179 . iter ( )
@@ -568,7 +568,7 @@ pub fn create_test_string_with_predicate(
568568 min_bytes : usize ,
569569 predicate : impl Fn ( & str ) -> bool ,
570570) -> String {
571- use rand:: { thread_rng , Rng } ;
571+ use rand:: { rng , Rng } ;
572572 // the string we accumulated thus far
573573 let mut result = String :: new ( ) ;
574574 // the tokens we added so we can backtrack
@@ -577,7 +577,7 @@ pub fn create_test_string_with_predicate(
577577 // try a few times to find a suitable token
578578 ' next: for _ in 0 ..8 {
579579 // pick a random token and provisionally add it
580- let i = thread_rng ( ) . gen_range ( 0 ..bpe. num_tokens ( ) ) as u32 ;
580+ let i = rng ( ) . random_range ( 0 ..bpe. num_tokens ( ) ) as u32 ;
581581 // We only use tokens that are valid UTF-8. This is true for ~99% of tokens in OpenAI's
582582 // token set. The chance of constructing a valid UTF-8 character across a token boundary
583583 // by picking random tokens is so small that it is unlikely to happen anyway.
@@ -603,8 +603,8 @@ pub fn create_test_string_with_predicate(
603603
604604#[ cfg( feature = "rand" ) ]
605605pub fn select_test_string ( text : & str , min_bytes : usize ) -> & str {
606- use rand:: { thread_rng , Rng } ;
607- let mut start = thread_rng ( ) . gen_range ( 0 ..text. len ( ) - min_bytes) ;
606+ use rand:: { rng , Rng } ;
607+ let mut start = rng ( ) . random_range ( 0 ..text. len ( ) - min_bytes) ;
608608 while !text. is_char_boundary ( start) {
609609 start -= 1 ;
610610 }
@@ -618,10 +618,10 @@ pub fn select_test_string(text: &str, min_bytes: usize) -> &str {
618618/// Generate test bytes by concatenating random tokens.
619619#[ cfg( feature = "rand" ) ]
620620pub fn create_test_bytes ( bpe : & BytePairEncoding , min_bytes : usize ) -> Vec < u8 > {
621- use rand:: { thread_rng , Rng } ;
621+ use rand:: { rng , Rng } ;
622622 let mut result = Vec :: new ( ) ;
623623 while result. len ( ) < min_bytes {
624- let i = thread_rng ( ) . gen_range ( 0 ..bpe. num_tokens ( ) ) ;
624+ let i = rng ( ) . random_range ( 0 ..bpe. num_tokens ( ) ) ;
625625 result. extend ( bpe. token_bytes ( i as u32 ) ) ;
626626 }
627627 result
0 commit comments