From: Alexis Laferrière Date: Wed, 4 Mar 2015 02:00:35 +0000 (-0500) Subject: lib: add an optimized `SequenceRead[E].rand` X-Git-Tag: v0.7.3~32^2~4 X-Git-Url: http://nitlanguage.org?hp=27be7768f904c3a2d953bab2a1ce040de877b34b lib: add an optimized `SequenceRead[E].rand` Signed-off-by: Alexis Laferrière --- diff --git a/lib/standard/math.nit b/lib/standard/math.nit index 4b6ed35..14c0e40 100644 --- a/lib/standard/math.nit +++ b/lib/standard/math.nit @@ -238,6 +238,15 @@ redef class Collection[ E ] end end +redef class SequenceRead[E] + # Optimized for large collections using `[]` + redef fun rand + do + assert not is_empty + return self[length.rand] + end +end + redef class Sys init do