Sha256: 7f2ddf8c8159517bca3d8047ec169a5d1a68f8f75ac5a6962e36b9d9e591ed21

Contents?: true

Size: 774 Bytes

Versions: 19

Compression:

Stored size: 774 Bytes

Contents

#include "ruby.h"
#include "cumo/narray.h"
#include "SFMT.h"

#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <time.h>
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif

static u_int64_t
random_seed()
{
    static int n = 0;
    struct timeval tv;

    gettimeofday(&tv, 0);
    return tv.tv_sec ^ tv.tv_usec ^ getpid() ^ n++;
}

static VALUE
cumo_na_s_srand(int argc, VALUE *argv, VALUE obj)
{
    VALUE vseed;
    u_int64_t seed;

    //rb_secure(4);
    if (rb_scan_args(argc, argv, "01", &vseed) == 0) {
        seed = random_seed();
    }
    else {
        seed = NUM2UINT64(vseed);
    }
    init_gen_rand(seed);

    return Qnil;
}

void
Init_cumo_na_rand() {
    rb_define_singleton_method(cNArray, "srand", cumo_na_s_srand, -1);
    init_gen_rand(0);
}

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
cumo-0.4.3 ext/cumo/narray/rand.c
cumo-0.4.2 ext/cumo/narray/rand.c
cumo-0.4.1 ext/cumo/narray/rand.c
cumo-0.4.0 ext/cumo/narray/rand.c
cumo-0.3.5 ext/cumo/narray/rand.c
cumo-0.3.4 ext/cumo/narray/rand.c
cumo-0.3.3 ext/cumo/narray/rand.c
cumo-0.3.2 ext/cumo/narray/rand.c
cumo-0.3.1 ext/cumo/narray/rand.c
cumo-0.3.0 ext/cumo/narray/rand.c
cumo-0.3.0.pre1 ext/cumo/narray/rand.c
cumo-0.2.5 ext/cumo/narray/rand.c
cumo-0.2.4 ext/cumo/narray/rand.c
cumo-0.2.3 ext/cumo/narray/rand.c
cumo-0.2.2 ext/cumo/narray/rand.c
cumo-0.2.1 ext/cumo/narray/rand.c
cumo-0.2.0 ext/cumo/narray/rand.c
cumo-0.1.2 ext/cumo/narray/rand.c
cumo-0.1.1 ext/cumo/narray/rand.c