Ruby 3.1.3p185 (2022-11-24 revision 1a6b16756e0ba6b95ab71a441357ed5484e33498)
Data Fields
rb_random_interface_t Struct Reference

PRNG algorithmic interface, analogous to Ruby level classes. More...

#include <random.h>

Data Fields

size_t default_seed_bits
 Number of bits of seed numbers. More...
 
rb_random_init_funcinit
 Initialiser function. More...
 
rb_random_get_int32_funcget_int32
 Function to obtain a random integer. More...
 
rb_random_get_bytes_funcget_bytes
 Function to obtain a series of random bytes. More...
 
rb_random_get_real_funcget_real
 Function to obtain a random double. More...
 

Detailed Description

PRNG algorithmic interface, analogous to Ruby level classes.

Definition at line 83 of file random.h.

Field Documentation

◆ default_seed_bits

size_t rb_random_interface_t::default_seed_bits

Number of bits of seed numbers.

Definition at line 85 of file random.h.

◆ get_bytes

rb_random_get_bytes_func* rb_random_interface_t::get_bytes

Function to obtain a series of random bytes.

If your PRNG have a native method to yield arbitrary number of bytes use that to implement this. But in case you lack such things, you can do so by using rb_rand_bytes_int32()

extern rb_random_get_int32_func your_get_int32_func;
void
your_get_byes_func(rb_random_t *rng, void *buf, size_t len)
{
rb_rand_bytes_int32(your_get_int32_func, rng, buf, len);
}
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...
Definition: random.c:1251
unsigned int rb_random_get_int32_func(rb_random_t *rng)
This is the type of functions called from your object's #rand method.
Definition: random.h:57
Base components of the random interface.
Definition: random.h:29

Definition at line 109 of file random.h.

◆ get_int32

rb_random_get_int32_func* rb_random_interface_t::get_int32

Function to obtain a random integer.

Definition at line 91 of file random.h.

◆ get_real

rb_random_get_real_func* rb_random_interface_t::get_real

Function to obtain a random double.

If your PRNG have a native method to yield a floating point random number use that to implement this. But in case you lack such things, you can do so by using rb_int_pair_to_real().

extern rb_random_get_int32_func your_get_int32_func;
void
your_get_real_func(rb_random_t *rng, int excl)
{
auto a = your_get_int32_func(rng);
auto b = your_get_int32_func(rng);
return rb_int_pair_to_real(a, b, excl);
}
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.
Definition: random.c:1105

Definition at line 129 of file random.h.

◆ init

rb_random_init_func* rb_random_interface_t::init

Initialiser function.

Definition at line 88 of file random.h.


The documentation for this struct was generated from the following file: