nitlanguage
/
nit.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
5338d0a
)
lib/math: nitunit `Collection::rand`
author
Jean Privat
<jean@pryen.org>
Tue, 5 May 2015 18:23:57 +0000
(14:23 -0400)
committer
Jean Privat
<jean@pryen.org>
Tue, 5 May 2015 18:23:57 +0000
(14:23 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>
lib/standard/math.nit
patch
|
blob
|
history
diff --git
a/lib/standard/math.nit
b/lib/standard/math.nit
index
2b55dca
..
b6f7153
100644
(file)
--- a/
lib/standard/math.nit
+++ b/
lib/standard/math.nit
@@
-241,6
+241,11
@@
end
redef class Collection[ E ]
# Return a random element form the collection
# There must be at least one element in the collection
+ #
+ # ~~~
+ # var x = [1,2,3].rand
+ # assert x == 1 or x == 2 or x == 3
+ # ~~~
fun rand: E
do
if is_empty then abort