Class: Random
- Inherits:
-
Object
- Object
- Random
- Defined in:
- lib/kmat/random.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.randn(*args) ⇒ Object
80 81 82 |
# File 'lib/kmat/random.rb', line 80 def randn(*args) $MatRandom.randn(*args) end |
.srand(*args) ⇒ Object
76 77 78 79 |
# File 'lib/kmat/random.rb', line 76 def srand(*args) @kmat_stored = false kmat_srand_org(*args) end |
Instance Method Details
#kmat_vt_rand(vt, arg = nil) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/kmat/random.rb', line 52 def kmat_vt_rand(vt, arg=nil) case Mat.vt_refine(vt) when :float _kmat_rand_d(arg) when :complex _kmat_rand_z(arg) when :int _kmat_rand_i(arg) when :bool _kmat_rand_b(arg) when :object _kmat_rand_v(arg) else raise Mat::InternalError, 'unknown value type' end end |
#randn(*args) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'ext/kmat/smat/boxmuller.c', line 53
static VALUE
km_random_randn(int argc, VALUE *argv, VALUE random)
{
rb_check_arity(argc, 0, 2);
if ( argc == 0 ) {
return rb_float_new(km_rand_normal(random));
} else if ( argc == 2 ) {
return rb_float_new(NUM2DBL(argv[0]) + km_rand_normal(random) * sqrt(NUM2DBL(argv[1])));
} else {
rb_raise(rb_eArgError, "when mean or standard deviation is specified, the other must be specified");
}
}
|