Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update lib/stdlib/core/list.opa

added List.random_elt
  • Loading branch information...
commit 5a2a7cedd780cd59b3c9f0c3432d972fc021c56a 1 parent ad16c1f
@hbbio hbbio authored
Showing with 3 additions and 0 deletions.
  1. +3 −0  lib/stdlib/core/list.opa
View
3  lib/stdlib/core/list.opa
@@ -261,6 +261,9 @@ List = {{
| [] -> none
| [hd | tl ] -> if Int.equals(n, 0) then some(hd) else get(n - 1, tl)
+ random_elt(l: list('a)): option('a) =
+ get(Random.int(length(l)), l)
+
/**
* Get and remove the [nth] element of a list.
*
Please sign in to comment.
Something went wrong with that request. Please try again.