summaryrefslogtreecommitdiff
path: root/src/z-rand.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/z-rand.hpp')
-rw-r--r--src/z-rand.hpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/z-rand.hpp b/src/z-rand.hpp
index bbf14584..cac28167 100644
--- a/src/z-rand.hpp
+++ b/src/z-rand.hpp
@@ -65,3 +65,23 @@ s32b rand_range(s32b a, s32b b);
* Note: rand_spread(A,D) == rand_range(A-D,A+D)
*/
s32b rand_spread(s32b a, s32b d);
+
+/**
+ * Choose a random element in from the given container.
+ * The container, C, must fulfill the Container concept
+ * whose iterators fulfill the RandomIterator concept.
+ **/
+template <class C> typename C::const_iterator uniform_element(C const &c)
+{
+ return c.begin() + rand_int(c.size());
+}
+
+/**
+ * Choose a random element in from the given container.
+ * The container, C, must fulfill the Container concept
+ * whose iterators fulfill the RandomIterator concept.
+ **/
+template <class C> typename C::iterator uniform_element(C &c)
+{
+ return c.begin() + rand_int(c.size());
+}