diff options
author | Chris AtLee <chris.atlee@shopify.com> | 2021-11-09 09:57:23 -0500 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2021-12-20 00:50:46 +0900 |
commit | 1dd10e189274546689c0b59f6a76849b2808f255 (patch) | |
tree | c22b9fca7d13b68302945ff5b3ab0dc020838571 /random.c | |
parent | 12ad53f41ff7956d12bd96ee2145355d11232a70 (diff) |
[DOC] Add documentation for Random.rand and Random.seed
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/5098
Diffstat (limited to 'random.c')
-rw-r--r-- | random.c | 21 |
1 files changed, 18 insertions, 3 deletions
@@ -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) { |