2 #define RUBY_RANDOM_H 1
24 #define RUBY_RANDOM_INTERFACE_VERSION_MAJOR 1
25 #define RUBY_RANDOM_INTERFACE_VERSION_MINOR 0
27 #define RUBY_RANDOM_PASTE_VERSION_SUFFIX(x, y, z) x##_##y##_##z
28 #define RUBY_RANDOM_WITH_VERSION_SUFFIX(name, major, minor) \
29 RUBY_RANDOM_PASTE_VERSION_SUFFIX(name, major, minor)
30 #define rb_random_data_type \
31 RUBY_RANDOM_WITH_VERSION_SUFFIX(rb_random_data_type, \
32 RUBY_RANDOM_INTERFACE_VERSION_MAJOR, \
33 RUBY_RANDOM_INTERFACE_VERSION_MINOR)
34 #define RUBY_RANDOM_INTERFACE_VERSION_INITIALIZER \
35 {RUBY_RANDOM_INTERFACE_VERSION_MAJOR, RUBY_RANDOM_INTERFACE_VERSION_MINOR}
36 #define RUBY_RANDOM_INTERFACE_VERSION_MAJOR_MAX 0xff
37 #define RUBY_RANDOM_INTERFACE_VERSION_MINOR_MAX 0xff
122 uint8_t major, minor;
182 #define RB_RANDOM_INTERFACE_DECLARE(prefix) \
183 static void prefix##_init(rb_random_t *, const uint32_t *, size_t); \
184 static void prefix##_init_int32(rb_random_t *, uint32_t); \
185 static unsigned int prefix##_get_int32(rb_random_t *); \
186 static void prefix##_get_bytes(rb_random_t *, void *, size_t)
192 #define RB_RANDOM_INTERFACE_DECLARE_WITH_REAL(prefix) \
193 RB_RANDOM_INTERFACE_DECLARE(prefix); \
194 static double prefix##_get_real(rb_random_t *, int)
210 #define RB_RANDOM_INTERFACE_DEFINE(prefix) \
211 RUBY_RANDOM_INTERFACE_VERSION_INITIALIZER, 0, \
213 prefix##_init_int32, \
214 prefix##_get_int32, \
221 #define RB_RANDOM_INTERFACE_DEFINE_WITH_REAL(prefix) \
222 RB_RANDOM_INTERFACE_DEFINE(prefix), \
225 #define RB_RANDOM_DEFINE_INIT_INT32_FUNC(prefix) \
226 static void prefix##_init_int32(rb_random_t *rnd, uint32_t data) \
228 prefix##_init(rnd, &data, 1); \
231 #if defined _WIN32 && !defined __CYGWIN__
233 # define RB_RANDOM_PARENT 0
256 # define RB_RANDOM_PARENT &rb_random_data_type
265 #define RB_RANDOM_DATA_INIT_PARENT(random_data) \
266 rbimpl_random_data_init_parent(&random_data)
337 const void *ret = t->data;
354 #if defined _WIN32 && !defined __CYGWIN__
#define RBIMPL_ASSERT_OR_ASSUME(...)
This is either RUBY_ASSERT or RBIMPL_ASSUME, depending on RUBY_DEBUG.
#define RUBY_EXTERN
Declaration of externally visible global variables.
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
char * ptr
Pointer to the underlying memory region, of at least capa bytes.
int len
Length of the buffer.
static const rb_random_interface_t * rb_rand_if(VALUE obj)
Queries the interface of the passed random object.
const rb_data_type_t rb_random_data_type
The data that holds the backend type of rb_cRandom.
void rb_random_mark(void *ptr)
This is the implementation of rb_data_type_struct::dmark for rb_random_data_type.
void rb_random_get_bytes_func(rb_random_t *rng, void *buf, size_t len)
This is the type of functions called from your object's #bytes method.
void rb_random_init_func(rb_random_t *rng, const uint32_t *buf, size_t len)
This is the type of functions called when your random object is initialised.
void rb_rand_bytes_int32(rb_random_get_int32_func *func, rb_random_t *prng, void *buff, size_t size)
Repeatedly calls the passed function over and over again until the passed buffer is filled with rando...
unsigned int rb_random_get_int32_func(rb_random_t *rng)
This is the type of functions called from your object's #rand method.
const rb_data_type_t rb_random_data_type_t
This is the type of rb_random_data_type.
double rb_int_pair_to_real(uint32_t a, uint32_t b, int excl)
Generates a 64 bit floating point number by concatenating two 32bit unsigned integers.
double rb_random_get_real_func(rb_random_t *rng, int excl)
This is the type of functions called from your object's #rand method.
void rb_random_init_int32_func(rb_random_t *rng, uint32_t data)
This is the type of functions called when your random object is initialised.
void rb_random_base_init(rb_random_t *rnd)
Initialises an allocated rb_random_t instance.
#define RBIMPL_ATTR_NOALIAS()
Wraps (or simulates) __declspec((noalias))
#define RBIMPL_ATTR_NONNULL(list)
Wraps (or simulates) __attribute__((nonnull))
#define inline
Old Visual Studio versions do not support the inline keyword, so we need to define it to be __inline.
#define RBIMPL_ATTR_PURE_UNLESS_DEBUG()
Enables RBIMPL_ATTR_PURE if and only if.
static bool RTYPEDDATA_P(VALUE obj)
Checks whether the passed object is RTypedData or RData.
static const struct rb_data_type_struct * RTYPEDDATA_TYPE(VALUE obj)
Queries for the type of given object.
This is the struct that holds necessary info for a struct.
PRNG algorithmic interface, analogous to Ruby level classes.
rb_random_init_func * init
Function to initialize from uint32_t array.
rb_random_init_int32_func * init_int32
Function to initialize from single uint32_t.
size_t default_seed_bits
Number of bits of seed numbers.
rb_random_get_int32_func * get_int32
Function to obtain a random integer.
uint16_t flags
Reserved flags.
rb_random_get_real_func * get_real
Function to obtain a random double.
rb_random_get_bytes_func * get_bytes
Function to obtain a series of random bytes.
Base components of the random interface.
VALUE seed
Seed, passed through e.g.
uintptr_t VALUE
Type that represents a Ruby object.