Blender V4.5
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)
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_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_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)
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)
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)

Detailed Description

Random number functions.

Definition in file BLI_rand.h.

Typedef Documentation

◆ RNG

typedef struct RNG RNG

Definition at line 21 of file BLI_rand.h.

◆ RNG_THREAD_ARRAY

typedef struct RNG_THREAD_ARRAY RNG_THREAD_ARRAY

Definition at line 24 of file BLI_rand.h.

Function Documentation

◆ BLI_array_randomize()

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

◆ BLI_bitmap_randomize()

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

◆ 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 226 of file rand.cc.

References BLI_halton_1d(), and halton_ex().

Referenced by BLI_halton_1d(), and BLI_rng_shuffle_bitmap().

◆ BLI_halton_2d()

void BLI_halton_2d ( const unsigned int prime[2],
double offset[2],
int n,
double * 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 281 of file rand.cc.

References BLI_hammersley_1d(), and radical_inverse().

Referenced by BLI_hammersley_1d(), BLI_rng_shuffle_bitmap(), and hammersley_create().

◆ BLI_hash_frand()

float BLI_hash_frand ( unsigned int seed)

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

Definition at line 148 of file rand.cc.

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

Referenced by BLI_hash_frand(), BLI_rng_shuffle_bitmap(), and modify_mesh().

◆ BLI_rng_free()

◆ BLI_rng_get_char_n()

◆ BLI_rng_get_double()

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

Definition at line 83 of file rand.cc.

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

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

◆ BLI_rng_get_float()

◆ BLI_rng_get_int()

◆ BLI_rng_get_tri_sample_float_v2()

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] )

◆ BLI_rng_get_uint()

◆ BLI_rng_new()

◆ BLI_rng_new_srandom()

◆ 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()

◆ 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 141 of file rand.cc.

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

Referenced by BLI_rng_shuffle_bitmap(), BLI_rng_skip(), 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 )

Use a hash table to create better seed.

Definition at line 63 of file rand.cc.

References BLI_rng_srandom(), RNG::rng, and blender::RandomNumberGenerator::seed_random().

Referenced by BKE_brush_system_init(), BLI_hash_frand(), BLI_rng_srandom(), and BLI_rng_threaded_new().

◆ BLI_rng_thread_rand()

int BLI_rng_thread_rand ( RNG_THREAD_ARRAY * rngarr,
int thread )

◆ BLI_rng_threaded_free()

void BLI_rng_threaded_free ( struct RNG_THREAD_ARRAY * rngarr)

Definition at line 190 of file rand.cc.

References BLI_rng_threaded_free().

Referenced by BLI_rng_shuffle_bitmap(), BLI_rng_threaded_free(), and 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 178 of file rand.cc.

References BLENDER_MAX_THREADS, BLI_rng_srandom(), BLI_rng_threaded_new(), i, and RNG_THREAD_ARRAY::rng_tab.

Referenced by BLI_rng_shuffle_bitmap(), BLI_rng_threaded_new(), and RE_texture_rng_init().