File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
frameworks/Rust/hyperlane/src Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -207,7 +207,8 @@ pub async fn all_world_row() -> Vec<PgRow> {
207207#[ inline]
208208pub async fn get_some_row_id ( limit : Queries , db_pool : & DbPoolConnection ) -> Vec < QueryRow > {
209209 let mut res: Vec < QueryRow > = Vec :: with_capacity ( limit as usize ) ;
210- for id in 0 ..limit {
210+ let id_list: Vec < i32 > = get_random_id_list ( limit) ;
211+ for id in id_list {
211212 let tem: QueryRow = query_world_row ( db_pool, id) . await ;
212213 res. push ( tem) ;
213214 }
Original file line number Diff line number Diff line change @@ -22,3 +22,16 @@ pub fn get_random_id() -> Queries {
2222 let random_id: Queries = rand. generate :: < Queries > ( ) % ( RANDOM_MAX as Queries + 1 ) ;
2323 random_id
2424}
25+
26+ #[ inline]
27+ pub fn get_random_id_list ( limit : Queries ) -> Vec < i32 > {
28+ let mut id_list: Vec < i32 > = ( 1 ..=limit) . collect ( ) ;
29+ let mut rng: WyRand = WyRand :: new ( ) ;
30+ let len: usize = id_list. len ( ) ;
31+ for i in ( 1 ..len) . rev ( ) {
32+ let j = rng. generate_range ( 0 ..=i as u32 ) as usize ;
33+ id_list. swap ( i, j) ;
34+ }
35+ id_list. truncate ( limit as usize ) ;
36+ id_list
37+ }
You can’t perform that action at this time.
0 commit comments