summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris AtLee <chris.atlee@shopify.com>2021-11-09 09:57:23 -0500
committerNobuyoshi Nakada <nobu@ruby-lang.org>2021-12-20 00:50:46 +0900
commit1dd10e189274546689c0b59f6a76849b2808f255 (patch)
treec22b9fca7d13b68302945ff5b3ab0dc020838571
parent12ad53f41ff7956d12bd96ee2145355d11232a70 (diff)
[DOC] Add documentation for Random.rand and Random.seed
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/5098
-rw-r--r--random.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/random.c b/random.c
index bf9479168b..f3dec5cca2 100644
--- a/random.c
+++ b/random.c
@@ -1293,6 +1293,21 @@ random_s_bytes(VALUE obj, VALUE len)
return rand_bytes(&random_mt_if, rnd, NUM2LONG(rb_to_int(len)));
}
+/*
+ * call-seq: Random.seed -> integer
+ *
+ * Returns the seed value used to initialize the Ruby system PRNG.
+ * This may be used to initialize another generator with the same
+ * state at a later time, causing it to produce the same sequence of
+ * numbers.
+ *
+ * Random.seed #=> 1234
+ * prng1 = Random.new(Random.seed)
+ * prng1.seed #=> 1234
+ * prng1.rand(100) #=> 47
+ * Random.seed #=> 1234
+ * Random.rand(100) #=> 47
+ */
static VALUE
random_s_seed(VALUE obj)
{
@@ -1646,10 +1661,10 @@ rb_f_rand(int argc, VALUE *argv, VALUE obj)
* Random.rand(max) -> number
* Random.rand(range) -> number
*
- * Generates a random number by the default PRNG.
- * See Random#rand.
+ * Returns a random number using the Ruby system PRNG.
+ *
+ * See also Random#rand.
*/
-
static VALUE
random_s_rand(int argc, VALUE *argv, VALUE obj)
{