Blender  V3.3
Typedefs | Functions
BLI_rand.h File Reference

Random number functions. More...

#include "BLI_compiler_attrs.h"
#include "BLI_sys_types.h"

Go to the source code of this file.

Typedefs

typedef struct RNG RNG
 
typedef struct RNG_THREAD_ARRAY RNG_THREAD_ARRAY
 

Functions

struct RNGBLI_rng_new (unsigned int seed)
 
struct RNGBLI_rng_new_srandom (unsigned int seed)
 
struct RNGBLI_rng_copy (struct RNG *rng) ATTR_NONNULL(1)
 
void BLI_rng_free (struct RNG *rng) ATTR_NONNULL(1)
 
void BLI_rng_seed (struct RNG *rng, unsigned int seed) ATTR_NONNULL(1)
 
void BLI_rng_srandom (struct RNG *rng, unsigned int seed) ATTR_NONNULL(1)
 
void BLI_rng_get_char_n (RNG *rng, char *bytes, size_t bytes_len) ATTR_NONNULL(1
 
void int BLI_rng_get_int (struct RNG *rng) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
 
unsigned int BLI_rng_get_uint (struct RNG *rng) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
 
double BLI_rng_get_double (struct RNG *rng) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
 
float BLI_rng_get_float (struct RNG *rng) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
 
void BLI_rng_get_float_unit_v2 (struct RNG *rng, float v[2]) ATTR_NONNULL(1
 
void void BLI_rng_get_float_unit_v3 (struct RNG *rng, float v[3]) ATTR_NONNULL(1
 
void void void BLI_rng_get_tri_sample_float_v2 (struct RNG *rng, const float v1[2], const float v2[2], const float v3[2], float r_pt[2]) ATTR_NONNULL()
 
void BLI_rng_get_tri_sample_float_v3 (RNG *rng, const float v1[3], const float v2[3], const float v3[3], float r_pt[3]) ATTR_NONNULL()
 
void BLI_rng_shuffle_array (struct RNG *rng, void *data, unsigned int elem_size_i, unsigned int elem_num) ATTR_NONNULL(1
 
void void BLI_rng_shuffle_bitmap (struct RNG *rng, unsigned int *bitmap, unsigned int bits_num) ATTR_NONNULL(1
 
void void void BLI_rng_skip (struct RNG *rng, int n) ATTR_NONNULL(1)
 
void BLI_array_frand (float *ar, int count, unsigned int seed)
 
float BLI_hash_frand (unsigned int seed) ATTR_WARN_UNUSED_RESULT
 
void BLI_array_randomize (void *data, unsigned int elem_size, unsigned int elem_num, unsigned int seed)
 
void BLI_bitmap_randomize (unsigned int *bitmap, unsigned int bits_num, unsigned int seed) ATTR_NONNULL(1)
 
void BLI_thread_srandom (int thread, unsigned int seed)
 
int BLI_thread_rand (int thread) ATTR_WARN_UNUSED_RESULT
 
float BLI_thread_frand (int thread) ATTR_WARN_UNUSED_RESULT
 
RNG_THREAD_ARRAYBLI_rng_threaded_new (void)
 
void BLI_rng_threaded_free (struct RNG_THREAD_ARRAY *rngarr) ATTR_NONNULL(1)
 
int BLI_rng_thread_rand (RNG_THREAD_ARRAY *rngarr, int thread) ATTR_WARN_UNUSED_RESULT
 
void BLI_halton_1d (unsigned int prime, double offset, int n, double *r)
 
void BLI_halton_2d (const unsigned int prime[2], double offset[2], int n, double *r)
 
void BLI_halton_3d (const unsigned int prime[3], double offset[3], int n, double *r)
 
void BLI_hammersley_1d (unsigned int n, double *r)
 
void BLI_halton_2d_sequence (const unsigned int prime[2], double offset[2], int n, double *r)
 
void BLI_hammersley_2d_sequence (unsigned int n, double *r)
 

Detailed Description

Random number functions.

Definition in file BLI_rand.h.

Typedef Documentation

◆ RNG

typedef struct RNG RNG

Definition at line 1 of file BLI_rand.h.

◆ RNG_THREAD_ARRAY

Definition at line 1 of file BLI_rand.h.

Function Documentation

◆ BLI_array_frand()

void BLI_array_frand ( float ar,
int  count,
unsigned int  seed 
)

Fill an array with random numbers.

Definition at line 169 of file rand.cc.

References BLI_rng_get_float(), BLI_rng_srandom(), count, and seed.

◆ BLI_array_randomize()

void BLI_array_randomize ( void data,
unsigned int  elem_size,
unsigned int  elem_num,
unsigned int  seed 
)

Shuffle an array randomly using the given seed contents. This routine does not use nor modify the state of the BLI random number generator.

Definition at line 188 of file rand.cc.

References BLI_rng_seed(), BLI_rng_shuffle_array(), data, and seed.

Referenced by edbm_select_random_exec(), gpencil_select_random_exec(), lattice_select_random_exec(), modifyMesh(), object_select_random_exec(), psys_thread_context_init_distribute(), random_heap_helper(), random_heap_reinsert_helper(), random_heapsimple_helper(), and testbuffer_list_data_randomize().

◆ BLI_bitmap_randomize()

void BLI_bitmap_randomize ( unsigned int *  bitmap,
unsigned int  bits_num,
unsigned int  seed 
)

Definition at line 199 of file rand.cc.

References BLI_rng_seed(), BLI_rng_shuffle_bitmap(), and seed.

Referenced by curve_select_random_exec().

◆ BLI_halton_1d()

void BLI_halton_1d ( unsigned int  prime,
double  offset,
int  n,
double r 
)

Return the _n_th number of the given low-discrepancy sequence.

Definition at line 287 of file rand.cc.

References double(), halton_ex(), offset, and r.

Referenced by EEVEE_materials_init(), workbench_volume_modifier_cache_populate(), and workbench_volume_object_cache_populate().

◆ BLI_halton_2d()

void BLI_halton_2d ( const unsigned int  prime[2],
double  offset[2],
int  n,
double r 
)

◆ BLI_halton_2d_sequence()

void BLI_halton_2d_sequence ( const unsigned int  prime[2],
double  offset[2],
int  n,
double r 
)

Return the whole low-discrepancy sequence up to n.

Definition at line 325 of file rand.cc.

References double(), halton_ex(), offset, and r.

◆ BLI_halton_3d()

void BLI_halton_3d ( const unsigned int  prime[3],
double  offset[3],
int  n,
double r 
)

◆ BLI_hammersley_1d()

void BLI_hammersley_1d ( unsigned int  n,
double r 
)

Definition at line 353 of file rand.cc.

References r, and radical_inverse().

Referenced by create_disk_samples(), and hammersley_create().

◆ BLI_hammersley_2d_sequence()

void BLI_hammersley_2d_sequence ( unsigned int  n,
double r 
)

Definition at line 358 of file rand.cc.

References double(), r, and radical_inverse().

◆ BLI_hash_frand()

float BLI_hash_frand ( unsigned int  seed)

Return a pseudo-random (hash) float from an integer value

Definition at line 180 of file rand.cc.

References BLI_rng_get_float(), BLI_rng_srandom(), and seed.

Referenced by modifyMesh().

◆ BLI_rng_copy()

struct RNG* BLI_rng_copy ( struct RNG rng)

Definition at line 53 of file rand.cc.

Referenced by BKE_partdeflect_copy().

◆ BLI_rng_free()

void BLI_rng_free ( struct RNG rng)

◆ BLI_rng_get_char_n()

void BLI_rng_get_char_n ( RNG rng,
char *  bytes,
size_t  bytes_len 
)

◆ BLI_rng_get_double()

double BLI_rng_get_double ( struct RNG rng)
Returns
Random value (0..1), but never 1.0.

Definition at line 88 of file rand.cc.

References blender::RandomNumberGenerator::get_double(), and RNG::rng.

Referenced by BLI_jitter_init(), hammersley_create(), and particles_fluid_step().

◆ BLI_rng_get_float()

float BLI_rng_get_float ( struct RNG rng)

◆ BLI_rng_get_float_unit_v2()

void BLI_rng_get_float_unit_v2 ( struct RNG rng,
float  v[2] 
)

◆ BLI_rng_get_float_unit_v3()

void void BLI_rng_get_float_unit_v3 ( struct RNG rng,
float  v[3] 
)

Referenced by object_rand_transverts().

◆ BLI_rng_get_int()

void int BLI_rng_get_int ( struct RNG rng)

◆ BLI_rng_get_tri_sample_float_v2()

void void void BLI_rng_get_tri_sample_float_v2 ( struct RNG rng,
const float  v1[2],
const float  v2[2],
const float  v3[2],
float  r_pt[2] 
)

Generate a random point inside given tri.

Definition at line 108 of file rand.cc.

References copy_v2_v2(), blender::RandomNumberGenerator::get_triangle_sample(), RNG::rng, v1, and v2.

Referenced by BKE_mesh_remap_calc_polys_from_mesh().

◆ BLI_rng_get_tri_sample_float_v3()

void BLI_rng_get_tri_sample_float_v3 ( RNG rng,
const float  v1[3],
const float  v2[3],
const float  v3[3],
float  r_pt[3] 
)

◆ BLI_rng_get_uint()

unsigned int BLI_rng_get_uint ( struct RNG rng)

◆ BLI_rng_new()

struct RNG* BLI_rng_new ( unsigned int  seed)

◆ BLI_rng_new_srandom()

struct RNG* BLI_rng_new_srandom ( unsigned int  seed)

◆ BLI_rng_seed()

void BLI_rng_seed ( struct RNG rng,
unsigned int  seed 
)

◆ BLI_rng_shuffle_array()

void BLI_rng_shuffle_array ( struct RNG rng,
void data,
unsigned int  elem_size_i,
unsigned int  elem_num 
)

◆ BLI_rng_shuffle_bitmap()

void void BLI_rng_shuffle_bitmap ( struct RNG rng,
unsigned int *  bitmap,
unsigned int  bits_num 
)

◆ BLI_rng_skip()

void void void BLI_rng_skip ( struct RNG rng,
int  n 
)

Note that skipping is as slow as generating n numbers! Simulate getting n random values.

Note
Useful when threaded code needs consistent values, independent of task division.

Definition at line 162 of file rand.cc.

References RNG::rng, and blender::RandomNumberGenerator::skip().

Referenced by distribute_children_exec(), distribute_from_faces_exec(), distribute_from_verts_exec(), distribute_from_volume_exec(), exec_distribute_child(), and exec_distribute_parent().

◆ BLI_rng_srandom()

void BLI_rng_srandom ( struct RNG rng,
unsigned int  seed 
)

◆ BLI_rng_thread_rand()

int BLI_rng_thread_rand ( RNG_THREAD_ARRAY rngarr,
int  thread 
)

Definition at line 256 of file rand.cc.

References BLI_rng_get_int(), and RNG_THREAD_ARRAY::rng_tab.

Referenced by texnoise().

◆ BLI_rng_threaded_free()

void BLI_rng_threaded_free ( struct RNG_THREAD_ARRAY rngarr)

Definition at line 251 of file rand.cc.

References MEM_freeN.

Referenced by RE_texture_rng_exit().

◆ BLI_rng_threaded_new()

RNG_THREAD_ARRAY* BLI_rng_threaded_new ( void  )

array versions for thread safe random generation

Definition at line 238 of file rand.cc.

References BLENDER_MAX_THREADS, BLI_rng_srandom(), MEM_mallocN, and RNG_THREAD_ARRAY::rng_tab.

Referenced by RE_texture_rng_init().

◆ BLI_thread_frand()

float BLI_thread_frand ( int  thread)

Return a pseudo-random number N where 0.0f<=N<1.0f Allows up to BLENDER_MAX_THREADS threads to address

Definition at line 229 of file rand.cc.

References BLI_rng_get_float(), and rng_tab.

Referenced by ED_region_do_draw().

◆ BLI_thread_rand()

int BLI_thread_rand ( int  thread)

Return a pseudo-random number N where 0<=N<(2^31) Allows up to BLENDER_MAX_THREADS threads to address

Definition at line 224 of file rand.cc.

References BLI_rng_get_int(), and rng_tab.

◆ BLI_thread_srandom()

void BLI_thread_srandom ( int  thread,
unsigned int  seed 
)

Better seed for the random number generator, using noise.c hash[] Allows up to BLENDER_MAX_THREADS threads to address

Definition at line 211 of file rand.cc.

References BLENDER_MAX_THREADS, BLI_rng_get_uint(), BLI_rng_seed(), hash, rng_tab, and seed.