Ruby  3.4.0dev (2024-12-06 revision 892c46283a5ea4179500d951c9d4866c0051f27b)
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...
 
struct {
   uint8_t   major
 
   uint8_t   minor
 
version
 Major/minor versions of this interface. More...
 
uint16_t flags
 Reserved flags. More...
 
rb_random_init_funcinit
 Function to initialize from uint32_t array. More...
 
rb_random_init_int32_funcinit_int32
 Function to initialize from single uint32_t. 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 114 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 116 of file random.h.

◆ flags

uint16_t rb_random_interface_t::flags

Reserved flags.

Definition at line 128 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);
}
int len
Length of the buffer.
Definition: io.h:8
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:1283
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:88
Base components of the random interface.
Definition: random.h:49

Definition at line 155 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 137 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:1137

Definition at line 175 of file random.h.

◆ init

rb_random_init_func* rb_random_interface_t::init

Function to initialize from uint32_t array.

Definition at line 131 of file random.h.

◆ init_int32

rb_random_init_int32_func* rb_random_interface_t::init_int32

Function to initialize from single uint32_t.

Definition at line 134 of file random.h.

◆ 

struct { ... } rb_random_interface_t::version

Major/minor versions of this interface.


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