In Files

  • random.c

Files

Class/Module Index [+]

Quicksearch

Random::Formatter

Generate a random number in the given range as Random does

prng.random_number       #=> 0.5816771641321361
prng.random_number(1000) #=> 485
prng.random_number(1..6) #=> 3
prng.rand                #=> 0.5816771641321361
prng.rand(1000)          #=> 485
prng.rand(1..6)          #=> 3

Public Instance Methods

random_number → float click to toggle source
random_number(max) → number
random_number(range) → number
rand → float
rand(max) → number
rand(range) → number

Generates formatted random number from raw random bytes. See Random#rand.

 
               static VALUE
rand_random_number(int argc, VALUE *argv, VALUE obj)
{
    rb_random_t *rnd = try_get_rnd(obj);
    VALUE v = rand_random(argc, argv, obj, rnd);
    if (NIL_P(v)) v = rand_random(0, 0, obj, rnd);
    else if (!v) invalid_argument(argv[0]);
    return v;
}
            
random_number → float click to toggle source
random_number(max) → number
random_number(range) → number

Generates formatted random number from raw random bytes. See Random#rand.

 
               static VALUE
rand_random_number(int argc, VALUE *argv, VALUE obj)
{
    rb_random_t *rnd = try_get_rnd(obj);
    VALUE v = rand_random(argc, argv, obj, rnd);
    if (NIL_P(v)) v = rand_random(0, 0, obj, rnd);
    else if (!v) invalid_argument(argv[0]);
    return v;
}