nitlanguage
/
nit.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
| inline |
side by side
lib: add an optimized `SequenceRead[E].rand`
[nit.git]
/
lib
/
standard
/
math.nit
diff --git
a/lib/standard/math.nit
b/lib/standard/math.nit
index
4b6ed35
..
14c0e40
100644
(file)
--- 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