From 8d7bb5cb59b1d2a01a74fcb334a38bc8eb745563 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Tue, 3 Mar 2015 21:00:35 -0500 Subject: [PATCH] lib: add an optimized `SequenceRead[E].rand` MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- lib/standard/math.nit | 9 +++++++++ 1 file changed, 9 insertions(+) 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 -- 1.7.9.5