From: Jean Privat Date: Tue, 5 May 2015 18:23:57 +0000 (-0400) Subject: lib/math: nitunit `Collection::rand` X-Git-Tag: v0.7.5~76^2~2 X-Git-Url: http://nitlanguage.org lib/math: nitunit `Collection::rand` Signed-off-by: Jean Privat --- diff --git a/lib/standard/math.nit b/lib/standard/math.nit index 2b55dca..b6f7153 100644 --- 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