@@ -171,9 +171,9 @@ pub fn find_hash_factor_for_dictionary(tokens: impl IntoIterator<Item = Vec<u8>>
171
171
use rand:: Rng ;
172
172
173
173
let all_tokens = tokens. into_iter ( ) . collect_vec ( ) ;
174
- let mut rnd = rand:: thread_rng ( ) ;
174
+ let mut rnd = rand:: rng ( ) ;
175
175
loop {
176
- let factor: u64 = rnd. gen ( ) ;
176
+ let factor: u64 = rnd. random ( ) ;
177
177
let mut seen = HashSet :: new ( ) ;
178
178
if all_tokens
179
179
. iter ( )
@@ -568,7 +568,7 @@ pub fn create_test_string_with_predicate(
568
568
min_bytes : usize ,
569
569
predicate : impl Fn ( & str ) -> bool ,
570
570
) -> String {
571
- use rand:: { thread_rng , Rng } ;
571
+ use rand:: { rng , Rng } ;
572
572
// the string we accumulated thus far
573
573
let mut result = String :: new ( ) ;
574
574
// the tokens we added so we can backtrack
@@ -577,7 +577,7 @@ pub fn create_test_string_with_predicate(
577
577
// try a few times to find a suitable token
578
578
' next: for _ in 0 ..8 {
579
579
// 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 ;
581
581
// We only use tokens that are valid UTF-8. This is true for ~99% of tokens in OpenAI's
582
582
// token set. The chance of constructing a valid UTF-8 character across a token boundary
583
583
// 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(
603
603
604
604
#[ cfg( feature = "rand" ) ]
605
605
pub 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) ;
608
608
while !text. is_char_boundary ( start) {
609
609
start -= 1 ;
610
610
}
@@ -618,10 +618,10 @@ pub fn select_test_string(text: &str, min_bytes: usize) -> &str {
618
618
/// Generate test bytes by concatenating random tokens.
619
619
#[ cfg( feature = "rand" ) ]
620
620
pub fn create_test_bytes ( bpe : & BytePairEncoding , min_bytes : usize ) -> Vec < u8 > {
621
- use rand:: { thread_rng , Rng } ;
621
+ use rand:: { rng , Rng } ;
622
622
let mut result = Vec :: new ( ) ;
623
623
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 ( ) ) ;
625
625
result. extend ( bpe. token_bytes ( i as u32 ) ) ;
626
626
}
627
627
result
0 commit comments