method
marshal_load
v1_9_2_180 -
Show latest stable
-
0 notes -
Class: Random
- 1_8_6_287
- 1_8_7_72
- 1_8_7_330
- 1_9_1_378
- 1_9_2_180 (0)
- 1_9_3_125 (0)
- 1_9_3_392 (0)
- 2_1_10 (0)
- 2_2_9 (0)
- 2_4_6 (0)
- 2_5_5 (0)
- 2_6_3 (0)
- What's this?
marshal_load(p1)
public
Hide source
static VALUE random_load(VALUE obj, VALUE dump) { rb_random_t *rnd = get_rnd(obj); struct MT *mt = &rnd->mt; VALUE state, left = INT2FIX(1), seed = INT2FIX(0); VALUE *ary; unsigned long x; Check_Type(dump, T_ARRAY); ary = RARRAY_PTR(dump); switch (RARRAY_LEN(dump)) { case 3: seed = ary[2]; case 2: left = ary[1]; case 1: state = ary[0]; break; default: rb_raise(rb_eArgError, "wrong dump data"); } memset(mt->state, 0, sizeof(mt->state)); if (FIXNUM_P(state)) { x = FIX2ULONG(state); mt->state[0] = (unsigned int)x; #if SIZEOF_LONG / SIZEOF_INT >= 2 mt->state[1] = (unsigned int)(x >> BITSPERDIG); #endif #if SIZEOF_LONG / SIZEOF_INT >= 3 mt->state[2] = (unsigned int)(x >> 2 * BITSPERDIG); #endif #if SIZEOF_LONG / SIZEOF_INT >= 4 mt->state[3] = (unsigned int)(x >> 3 * BITSPERDIG); #endif } else { BDIGIT *d; long len; Check_Type(state, T_BIGNUM); len = RBIGNUM_LEN(state); if (len > roomof(sizeof(mt->state), SIZEOF_BDIGITS)) { len = roomof(sizeof(mt->state), SIZEOF_BDIGITS); } #if SIZEOF_BDIGITS < SIZEOF_INT else if (len % DIGSPERINT) { d = RBIGNUM_DIGITS(state) + len; # if DIGSPERINT == 2 --len; x = *--d; # else x = 0; do { x = (x << BITSPERDIG) | *--d; } while (--len % DIGSPERINT); # endif mt->state[len / DIGSPERINT] = (unsigned int)x; } #endif if (len > 0) { d = BDIGITS(state) + len; do { --len; x = *--d; # if DIGSPERINT == 2 --len; x = (x << BITSPERDIG) | *--d; # elif SIZEOF_BDIGITS < SIZEOF_INT do { x = (x << BITSPERDIG) | *--d; } while (--len % DIGSPERINT); # endif mt->state[len / DIGSPERINT] = (unsigned int)x; } while (len > 0); } } x = NUM2ULONG(left); if (x > numberof(mt->state)) { rb_raise(rb_eArgError, "wrong value"); } mt->left = (unsigned int)x; mt->next = mt->state + numberof(mt->state) - x + 1; rnd->seed = rb_to_int(seed); return obj; }