Blender V4.3
blender::RandomNumberGenerator Class Reference

#include <BLI_rand.hh>

Public Member Functions

 RandomNumberGenerator (uint32_t seed=0)
 
void seed (uint32_t seed)
 
void seed_random (uint32_t seed)
 
uint32_t get_uint32 ()
 
int32_t get_int32 ()
 
uint64_t get_uint64 ()
 
int32_t get_int32 (int32_t max_exclusive)
 
double get_double ()
 
float get_float ()
 
template<typename T >
void shuffle (MutableSpan< T > values)
 
float3 get_barycentric_coordinates ()
 
int round_probabilistic (float x)
 
float2 get_unit_float2 ()
 
float3 get_unit_float3 ()
 
float2 get_triangle_sample (float2 v1, float2 v2, float2 v3)
 
float3 get_triangle_sample_3d (float3 v1, float3 v2, float3 v3)
 
void get_bytes (MutableSpan< char > r_bytes)
 
void skip (int64_t n)
 

Static Public Member Functions

static RandomNumberGenerator from_random_seed ()
 

Detailed Description

Definition at line 17 of file BLI_rand.hh.

Constructor & Destructor Documentation

◆ RandomNumberGenerator()

blender::RandomNumberGenerator::RandomNumberGenerator ( uint32_t seed = 0)
inline

Definition at line 22 of file BLI_rand.hh.

References seed.

Referenced by from_random_seed().

Member Function Documentation

◆ from_random_seed()

RandomNumberGenerator blender::RandomNumberGenerator::from_random_seed ( )
static

◆ get_barycentric_coordinates()

float3 blender::RandomNumberGenerator::get_barycentric_coordinates ( )
inline

Compute uniformly distributed barycentric coordinates.

Definition at line 105 of file BLI_rand.hh.

References get_float().

Referenced by blender::nodes::node_geo_distribute_points_on_faces_cc::sample_mesh_surface(), and blender::bke::mesh_surface_sample::sample_surface_points_spherical().

◆ get_bytes()

void blender::RandomNumberGenerator::get_bytes ( MutableSpan< char > r_bytes)

Definition at line 450 of file rand.cc.

References BLI_assert, and blender::MutableSpan< T >::size().

Referenced by BLI_rng_get_char_n().

◆ get_double()

double blender::RandomNumberGenerator::get_double ( )
inline
Returns
Random value (0..1), but never 1.0.

Definition at line 76 of file BLI_rand.hh.

References double(), and get_int32().

Referenced by BLI_rng_get_double().

◆ get_float()

◆ get_int32() [1/2]

◆ get_int32() [2/2]

int32_t blender::RandomNumberGenerator::get_int32 ( int32_t max_exclusive)
inline
Returns
Random value (0..N), but never N.

Definition at line 67 of file BLI_rand.hh.

References BLI_assert, and get_int32().

◆ get_triangle_sample()

float2 blender::RandomNumberGenerator::get_triangle_sample ( float2 v1,
float2 v2,
float2 v3 )

Generate a random point inside the given triangle.

Definition at line 412 of file rand.cc.

References get_float(), sample, v, and v2.

Referenced by BLI_rng_get_tri_sample_float_v2().

◆ get_triangle_sample_3d()

float3 blender::RandomNumberGenerator::get_triangle_sample_3d ( float3 v1,
float3 v2,
float3 v3 )

Definition at line 431 of file rand.cc.

References get_float(), sample, v, and v2.

Referenced by BLI_rng_get_tri_sample_float_v3().

◆ get_uint32()

uint32_t blender::RandomNumberGenerator::get_uint32 ( )
inline

◆ get_uint64()

uint64_t blender::RandomNumberGenerator::get_uint64 ( )
inline

Definition at line 59 of file BLI_rand.hh.

References get_uint32().

◆ get_unit_float2()

float2 blender::RandomNumberGenerator::get_unit_float2 ( )

Definition at line 392 of file rand.cc.

References cosf, float, get_float(), M_PI, and sinf.

Referenced by BLI_rng_get_float_unit_v2(), and TEST().

◆ get_unit_float3()

float3 blender::RandomNumberGenerator::get_unit_float3 ( )

Definition at line 398 of file rand.cc.

References cosf, float, get_float(), M_PI, sinf, sqrtf, x, y, and z().

Referenced by BLI_rng_get_float_unit_v3().

◆ round_probabilistic()

int blender::RandomNumberGenerator::round_probabilistic ( float x)

Round value to the next integer randomly. 4.9f is more likely to round to 5 than 4.6f.

Definition at line 383 of file rand.cc.

References BLI_assert, fractf(), get_float(), int, and round_up().

Referenced by blender::nodes::node_geo_distribute_points_on_faces_cc::sample_mesh_surface(), and blender::bke::mesh_surface_sample::sample_surface_points_spherical().

◆ seed()

void blender::RandomNumberGenerator::seed ( uint32_t seed)
inline

Set the seed for future random numbers.

Definition at line 36 of file BLI_rand.hh.

References seed, and x_.

Referenced by BLI_rng_new(), and BLI_rng_seed().

◆ seed_random()

void blender::RandomNumberGenerator::seed_random ( uint32_t seed)

Set a randomized hash of the value as seed.

Definition at line 374 of file rand.cc.

References get_uint32(), hash, and seed.

Referenced by BLI_rng_new_srandom(), BLI_rng_srandom(), and blender::bke::generate_unique_instance_ids().

◆ shuffle()

template<typename T >
void blender::RandomNumberGenerator::shuffle ( MutableSpan< T > values)
inline

Definition at line 89 of file BLI_rand.hh.

References BLI_assert, get_int32(), and INT32_MAX.

Referenced by TEST(), and TEST().

◆ skip()

void blender::RandomNumberGenerator::skip ( int64_t n)
inline

Simulate getting n random values.

Definition at line 136 of file BLI_rand.hh.

Referenced by BLI_rng_skip().


The documentation for this class was generated from the following files: