Class: PCGRandom
- Inherits:
-
Object
- Object
- PCGRandom
- Defined in:
- lib/pcg_random/version.rb,
ext/pcg_random/pcg_random.c
Constant Summary collapse
- VERSION =
"0.1.4"
- DEFAULT_SEED_BYTES =
INT2FIX(DEFAULT_SEED_BYTES)
Instance Attribute Summary collapse
- #seed ⇒ Object readonly
Class Method Summary collapse
-
.new_seed ⇒ Object
Returns a 16-byte integer that stores the seed value used to seed the initial state and sequence for the PCG generator.
-
.raw_seed(byte_size) ⇒ Object
Generates a random seed string represented as a sequence of bytes.
Instance Method Summary collapse
-
#initialize(*args) ⇒ Object
constructor
Internal - Initialize the requested instance using a pre-allocated ruby object (TypedStruct).
Constructor Details
#initialize(*args) ⇒ Object
Internal - Initialize the requested instance using a pre-allocated ruby object (TypedStruct). Sets the instance variables and relevant accessor methods where applicable.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'ext/pcg_random/pcg_random.c', line 110
static VALUE
pcg_func_init(int argc, VALUE *argv, VALUE self)
{
VALUE seed;
uint64_t cseeds[2];
pcg_rb_rand_t* rand_data = pcg_get_rand_type(self);
if(argc == 0)
{
seed = DEFAULT_SEED_VALUE;
}
else
{
rb_scan_args(argc, argv, "01", &seed);
}
rb_integer_pack(seed, (void *) cseeds, 2, sizeof(uint64_t), 0,
INTEGER_PACK_MSWORD_FIRST|INTEGER_PACK_NATIVE_BYTE_ORDER);
rand_data->seed.val = seed;
rand_data->seed.state = cseeds[0];
rand_data->seed.seq = cseeds[1];
pcg32_srandom_r(rand_data->rng, cseeds[0], cseeds[1]);
/* Add & set private instance variables */
rb_iv_set(self, "@seed", seed);
rb_iv_set(self, "state", LONG2NUM(rand_data->seed.state));
rb_iv_set(self, "sequence", LONG2NUM(rand_data->seed.seq));
return self;
}
|
Instance Attribute Details
#seed ⇒ Object (readonly)
Class Method Details
.new_seed ⇒ Object
Returns a 16-byte integer that stores the seed value used to seed the initial state and sequence for the PCG generator.
13 14 15 16 17 |
# File 'ext/pcg_random/pcg_seed.c', line 13
VALUE
pcg_func_new_seed(VALUE self)
{
return DEFAULT_SEED_VALUE;
}
|
.raw_seed(byte_size) ⇒ Object
Generates a random seed string represented as a sequence of bytes
24 25 26 27 28 29 30 31 32 33 |
# File 'ext/pcg_random/pcg_seed.c', line 24
VALUE
pcg_func_raw_seed(VALUE self, VALUE byte_size)
{
unsigned long n = NUM2ULONG(byte_size);
if(n == 0)
{
return rb_str_new2("\0");
}
return pcg_raw_seed_bytestr(n);
}
|