123456789101112131415161718192021222324(** An internal-only module factored out due to a circular dependency between core_array
and core_list. Contains code for permuting an array. *)open!ImportincludeArray0letpermute?(random_state=Random.State.default)?(pos=0)?lent=(* Copied from [Ordered_collection_common0] to avoid allocating a tuple when compiling
without flambda. *)lettotal_length=lengthtinletlen=matchlenwith|Somel->l|None->total_length-posinOrdered_collection_common0.check_pos_len_exn~pos~len~total_length;letnum_swaps=len-1infori=num_swapsdownto1doletthis_i=pos+iin(* [random_i] is drawn from [pos,this_i] *)letrandom_i=pos+Random.State.intrandom_state(i+1)inswaptthis_irandom_idone;;