mirror of
https://github.com/c-cube/iter.git
synced 2025-12-08 04:05:32 -05:00
Add shuffle.
This commit is contained in:
parent
964b5c61bd
commit
9ae652b004
3 changed files with 15 additions and 0 deletions
|
|
@ -707,6 +707,11 @@ let shuffle_array a =
|
||||||
a.(k) <- tmp;
|
a.(k) <- tmp;
|
||||||
done
|
done
|
||||||
|
|
||||||
|
let shuffle seq =
|
||||||
|
let a = to_array seq in
|
||||||
|
shuffle_array a ;
|
||||||
|
of_array a
|
||||||
|
|
||||||
let shuffle_buffer n seq k =
|
let shuffle_buffer n seq k =
|
||||||
let seq_front = take n seq in
|
let seq_front = take n seq in
|
||||||
let a = to_array seq_front in
|
let a = to_array seq_front in
|
||||||
|
|
|
||||||
|
|
@ -498,6 +498,11 @@ val random_list : 'a list -> 'a t
|
||||||
(** Infinite sequence of random elements of the list. Basically the
|
(** Infinite sequence of random elements of the list. Basically the
|
||||||
same as {!random_array}. *)
|
same as {!random_array}. *)
|
||||||
|
|
||||||
|
val shuffle : 'a t -> 'a t
|
||||||
|
(** [shuffle seq] returns a perfect shuffle of [seq].
|
||||||
|
Uses O(length seq) memory and time. Eager.
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
val shuffle_buffer : int -> 'a t -> 'a t
|
val shuffle_buffer : int -> 'a t -> 'a t
|
||||||
(** [shuffle_buffer n seq] returns a sequence of element of [seq] in random
|
(** [shuffle_buffer n seq] returns a sequence of element of [seq] in random
|
||||||
order. The shuffling is *not* uniform. Uses O(n) memory.
|
order. The shuffling is *not* uniform. Uses O(n) memory.
|
||||||
|
|
|
||||||
|
|
@ -446,6 +446,11 @@ val random_list : 'a list -> 'a t
|
||||||
(** Infinite sequence of random elements of the list. Basically the
|
(** Infinite sequence of random elements of the list. Basically the
|
||||||
same as {!random_array}. *)
|
same as {!random_array}. *)
|
||||||
|
|
||||||
|
val shuffle : 'a t -> 'a t
|
||||||
|
(** [shuffle seq] returns a perfect shuffle of [seq].
|
||||||
|
Uses O(length seq) memory and time. Eager.
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
val shuffle_buffer : n:int -> 'a t -> 'a t
|
val shuffle_buffer : n:int -> 'a t -> 'a t
|
||||||
(** [shuffle_buffer n seq] returns a sequence of element of [seq] in random
|
(** [shuffle_buffer n seq] returns a sequence of element of [seq] in random
|
||||||
order. The shuffling is not uniform. Uses O(n) memory.
|
order. The shuffling is not uniform. Uses O(n) memory.
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue