|
Blender
V2.93
|
#include <cmath>#include <cstdlib>#include <cstring>#include <ctime>#include "MEM_guardedalloc.h"#include "BLI_math.h"#include "BLI_rand.h"#include "BLI_rand.hh"#include "BLI_threads.h"#include "BLI_compiler_compat.h"#include "BLI_strict_flags.h"#include "BLI_sys_types.h"Go to the source code of this file.
Classes | |
| struct | RNG |
| struct | RNG_THREAD_ARRAY |
Namespaces | |
| blender | |
Macros | |
| #define | hash BLI_noise_hash_uchar_512 |
Functions | |
| RNG * | BLI_rng_new (unsigned int seed) |
| RNG * | BLI_rng_new_srandom (unsigned int seed) |
| RNG * | BLI_rng_copy (RNG *rng) |
| void | BLI_rng_free (RNG *rng) |
| void | BLI_rng_seed (RNG *rng, unsigned int seed) |
| void | BLI_rng_srandom (RNG *rng, unsigned int seed) |
| void | BLI_rng_get_char_n (RNG *rng, char *bytes, size_t bytes_len) |
| int | BLI_rng_get_int (RNG *rng) |
| unsigned int | BLI_rng_get_uint (RNG *rng) |
| double | BLI_rng_get_double (RNG *rng) |
| float | BLI_rng_get_float (RNG *rng) |
| void | BLI_rng_get_float_unit_v2 (RNG *rng, float v[2]) |
| void | BLI_rng_get_float_unit_v3 (RNG *rng, float v[3]) |
| void | BLI_rng_get_tri_sample_float_v2 (RNG *rng, const float v1[2], const float v2[2], const float v3[2], float r_pt[2]) |
| 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]) |
| void | BLI_rng_shuffle_array (RNG *rng, void *data, unsigned int elem_size_i, unsigned int elem_tot) |
| void | BLI_rng_skip (RNG *rng, int n) |
| void | BLI_array_frand (float *ar, int count, unsigned int seed) |
| float | BLI_hash_frand (unsigned int seed) |
| void | BLI_array_randomize (void *data, unsigned int elem_size, unsigned int elem_tot, unsigned int seed) |
| void | BLI_thread_srandom (int thread, unsigned int seed) |
| int | BLI_thread_rand (int thread) |
| float | BLI_thread_frand (int thread) |
| RNG_THREAD_ARRAY * | BLI_rng_threaded_new (void) |
| void | BLI_rng_threaded_free (struct RNG_THREAD_ARRAY *rngarr) |
| int | BLI_rng_thread_rand (RNG_THREAD_ARRAY *rngarr, int thread) |
| BLI_INLINE double | halton_ex (double invprimes, double *offset) |
| 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_halton_2d_sequence (const unsigned int prime[2], double offset[2], int n, double *r) |
| BLI_INLINE double | radical_inverse (unsigned int n) |
| void | BLI_hammersley_1d (unsigned int n, double *r) |
| void | BLI_hammersley_2d_sequence (unsigned int n, double *r) |
Variables | |
| unsigned char | BLI_noise_hash_uchar_512 [512] |
| static RNG | rng_tab [BLENDER_MAX_THREADS] |
| #define hash BLI_noise_hash_uchar_512 |
| void BLI_array_frand | ( | float * | ar, |
| int | count, | ||
| unsigned int | seed | ||
| ) |
Definition at line 189 of file rand.cc.
References BLI_rng_get_float(), BLI_rng_srandom(), count, and seed.
| void BLI_array_randomize | ( | void * | data, |
| unsigned int | elem_size, | ||
| unsigned int | elem_tot, | ||
| 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 208 of file rand.cc.
References BLI_rng_seed(), BLI_rng_shuffle_array(), data, and seed.
Referenced by edbm_select_random_exec(), modifyMesh(), psys_thread_context_init_distribute(), random_heap_helper(), random_heap_reinsert_helper(), random_heapsimple_helper(), and testbuffer_list_data_randomize().
Return the _n_th number of the given low-discrepancy sequence.
Definition at line 299 of file rand.cc.
References double(), halton_ex(), and r.
Referenced by EEVEE_materials_init(), workbench_volume_modifier_cache_populate(), and workbench_volume_object_cache_populate().
Definition at line 310 of file rand.cc.
References double(), halton_ex(), and r.
Referenced by eevee_lookdev_apply_taa(), EEVEE_sample_ellipse(), EEVEE_sample_rectangle(), and EEVEE_temporal_sampling_update_matrices().
Return the whole low-discrepancy sequence up to n.
Definition at line 337 of file rand.cc.
References double(), halton_ex(), and r.
Definition at line 323 of file rand.cc.
References double(), halton_ex(), and r.
Referenced by eevee_draw_scene(), EEVEE_random_rotation_m4(), EEVEE_render_draw(), EEVEE_sample_ball(), and EEVEE_volumes_set_jitter().
| void BLI_hammersley_1d | ( | unsigned int | n, |
| double * | r | ||
| ) |
Definition at line 365 of file rand.cc.
References r, and radical_inverse().
Referenced by create_disk_samples(), and hammersley_create().
| void BLI_hammersley_2d_sequence | ( | unsigned int | n, |
| double * | r | ||
| ) |
Definition at line 370 of file rand.cc.
References double(), r, and radical_inverse().
| float BLI_hash_frand | ( | unsigned int | seed | ) |
Return a pseudo-random (hash) float from an integer value
Definition at line 200 of file rand.cc.
References BLI_rng_get_float(), BLI_rng_srandom(), and seed.
Referenced by modifyMesh().
Definition at line 71 of file rand.cc.
Referenced by BKE_partdeflect_copy().
| void BLI_rng_free | ( | RNG * | rng | ) |
Definition at line 76 of file rand.cc.
Referenced by BKE_brush_system_exit(), BKE_mesh_remap_calc_polys_from_mesh(), BKE_partdeflect_free(), BKE_particle_init_rng(), BLI_jitter_init(), bmo_subdivide_edges_exec(), brush_add(), brush_add_count_iter_free(), cloth_build_springs(), blender::fn::mf_network_optimization::compute_node_hashes(), createFacepa(), curve_select_random(), blender::compositor::ScreenLensDistortionOperation::deinitExecution(), distribute_simple_children(), do_map(), dynamics_step(), find_nearest_points_test(), gpencil_primitive_exit(), gpencil_sculpt_brush_exit(), gpencil_session_free(), gpencil_stroke_path_animation(), hair_random(), hammersley_create(), init_keys(), init_mv_jit(), int4_ghash_tests(), lattice_select_random_exec(), make_duplis_particle_system(), modifyMesh(), multi_small_ghash_tests(), Freestyle::Noise::Noise(), object_rand_transverts(), object_select_random_exec(), paint_stroke_free(), param_stretch_end(), particles_fluid_step(), PE_free_random_generator(), pointcloud_random(), postTrans(), psys_tasks_free(), psys_thread_context_init_distribute(), randint_ghash_tests(), random_chunk_generate(), random_chunk_mutate_helper(), random_data_mutate_helper(), select_random_exec(), select_random_metaelems_exec(), and sort_bmelem_flag().
| void BLI_rng_get_char_n | ( | RNG * | rng, |
| char * | bytes, | ||
| size_t | bytes_len | ||
| ) |
Definition at line 94 of file rand.cc.
References blender::RandomNumberGenerator::get_bytes(), and RNG::rng.
Definition at line 112 of file rand.cc.
References blender::RandomNumberGenerator::get_double(), and RNG::rng.
Referenced by BLI_jitter_init(), hammersley_create(), and particles_fluid_step().
Definition at line 120 of file rand.cc.
References blender::RandomNumberGenerator::get_float(), and RNG::rng.
Referenced by basic_force_cb(), BKE_brush_jitter_pos(), BKE_brush_randomize_texture_coords(), BKE_particle_init_rng(), BLI_array_frand(), BLI_hash_frand(), BLI_thread_frand(), bmo_subdivide_edges_exec(), boid_body(), brush_add_count_iter(), brush_cut(), calculatePropRatio(), collision_response(), createFacepa(), curve_select_random(), distribute_children_exec(), distribute_from_faces_exec(), distribute_from_volume_exec(), distribute_simple_children(), find_internal_spring_target_vertex(), gpencil_apply_randomness(), gpencil_brush_randomize_apply(), gpencil_find_end_of_stroke_idx(), gpencil_primitive_update_strokes(), gpencil_stroke_addpoint(), hair_random(), init_mv_jit(), lattice_select_random_exec(), object_rand_transverts(), object_select_random_exec(), p_chart_stretch_minimize(), paint_brush_update(), pointcloud_random(), psys_thread_context_init_distribute(), rng_v3_round(), rule_average_speed(), rule_avoid_collision(), rule_fight(), select_random_exec(), select_random_metaelems_exec(), sort_bmelem_flag(), weightvg_do_map(), and wind_func().
Definition at line 125 of file rand.cc.
References copy_v2_v2(), blender::RandomNumberGenerator::get_unit_float2(), RNG::rng, and v.
Definition at line 130 of file rand.cc.
References copy_v3_v3(), blender::RandomNumberGenerator::get_unit_float3(), RNG::rng, and v.
| int BLI_rng_get_int | ( | RNG * | rng | ) |
Definition at line 99 of file rand.cc.
References blender::RandomNumberGenerator::get_int32(), and RNG::rng.
Referenced by BKE_particle_init_rng(), BLI_rng_thread_rand(), BLI_thread_rand(), make_duplis_particle_system(), multi_small_ghash_tests(), Freestyle::Noise::Noise(), and wind_func().
| void BLI_rng_get_tri_sample_float_v2 | ( | 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 138 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().
| 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] | ||
| ) |
Definition at line 144 of file rand.cc.
References copy_v3_v3(), blender::RandomNumberGenerator::get_triangle_sample_3d(), RNG::rng, v1, and v2.
| unsigned int BLI_rng_get_uint | ( | RNG * | rng | ) |
Definition at line 104 of file rand.cc.
References blender::RandomNumberGenerator::get_uint32(), and RNG::rng.
Referenced by BLI_rng_shuffle_array(), BLI_thread_srandom(), blender::fn::mf_network_optimization::compute_node_hash(), blender::fn::mf_network_optimization::compute_node_hashes(), init_keys(), int4_ghash_tests(), multi_small_ghash_tests_one(), rand_range_i(), randint_ghash_tests(), and testbuffer_list_state_random_data().
| RNG* BLI_rng_new | ( | unsigned int | seed | ) |
Definition at line 54 of file rand.cc.
References RNG::rng, seed, and blender::RandomNumberGenerator::seed().
Referenced by BKE_brush_system_init(), BKE_mesh_remap_calc_polys_from_mesh(), BLI_jitter_init(), calculatePropRatio(), blender::fn::mf_network_optimization::compute_node_hashes(), find_nearest_points_test(), gpencil_primitive_set_initdata(), gpencil_sculpt_brush_init(), gpencil_session_initpaint(), gpencil_stroke_path_animation(), hair_random(), hammersley_create(), init_keys(), init_mv_jit(), blender::compositor::ScreenLensDistortionOperation::initExecution(), int4_ghash_tests(), multi_small_ghash_tests(), Freestyle::Noise::Noise(), object_rand_transverts(), paint_brush_update(), param_stretch_begin(), PE_create_random_generator(), pointcloud_random(), precalculate_effector(), psys_task_init_distribute(), psys_task_init_path(), randint_ghash_tests(), random_chunk_generate(), random_chunk_mutate_helper(), and random_data_mutate_helper().
| RNG* BLI_rng_new_srandom | ( | unsigned int | seed | ) |
A version of BLI_rng_new that hashes the seed.
Definition at line 64 of file rand.cc.
References RNG::rng, seed, and blender::RandomNumberGenerator::seed_random().
Referenced by BKE_particle_init_rng(), bmo_subdivide_edges_exec(), brush_add(), brush_add_count_iter(), cloth_build_springs(), createFacepa(), curve_select_random(), distribute_simple_children(), do_map(), dynamics_step(), lattice_select_random_exec(), make_duplis_particle_system(), modifyMesh(), object_select_random_exec(), particles_fluid_step(), psys_thread_context_init_distribute(), select_random_exec(), select_random_metaelems_exec(), and sort_bmelem_flag().
| void BLI_rng_seed | ( | RNG * | rng, |
| unsigned int | seed | ||
| ) |
Definition at line 81 of file rand.cc.
References RNG::rng, seed, and blender::RandomNumberGenerator::seed().
Referenced by BLI_array_randomize(), and BLI_thread_srandom().
| void BLI_rng_shuffle_array | ( | RNG * | rng, |
| void * | data, | ||
| unsigned int | elem_size_i, | ||
| unsigned int | elem_tot | ||
| ) |
Definition at line 150 of file rand.cc.
References BLI_rng_get_uint(), data, and free().
Referenced by BLI_array_randomize().
| void BLI_rng_skip | ( | RNG * | rng, |
| int | n | ||
| ) |
Simulate getting n random values.
Definition at line 181 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().
| void BLI_rng_srandom | ( | RNG * | rng, |
| unsigned int | seed | ||
| ) |
Use a hash table to create better seed.
Definition at line 89 of file rand.cc.
References RNG::rng, seed, and blender::RandomNumberGenerator::seed_random().
Referenced by BKE_brush_system_init(), BLI_array_frand(), BLI_hash_frand(), BLI_rng_threaded_new(), gpencil_stroke_path_animation_preprocess_gaps(), and precalculate_effector().
| int BLI_rng_thread_rand | ( | RNG_THREAD_ARRAY * | rngarr, |
| int | thread | ||
| ) |
Definition at line 268 of file rand.cc.
References BLI_rng_get_int(), and RNG_THREAD_ARRAY::rng_tab.
Referenced by texnoise().
| void BLI_rng_threaded_free | ( | struct RNG_THREAD_ARRAY * | rngarr | ) |
| RNG_THREAD_ARRAY* BLI_rng_threaded_new | ( | void | ) |
array versions for thread safe random generation
Definition at line 250 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().
| 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 241 of file rand.cc.
References BLI_rng_get_float(), and rng_tab.
Referenced by ED_region_do_draw().
| 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 236 of file rand.cc.
References BLI_rng_get_int(), and rng_tab.
| 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 223 of file rand.cc.
References BLENDER_MAX_THREADS, BLI_rng_get_uint(), BLI_rng_seed(), hash, rng_tab, and seed.
| BLI_INLINE double halton_ex | ( | double | invprimes, |
| double * | offset | ||
| ) |
Definition at line 277 of file rand.cc.
Referenced by BLI_halton_1d(), BLI_halton_2d(), BLI_halton_2d_sequence(), and BLI_halton_3d().
| BLI_INLINE double radical_inverse | ( | unsigned int | n | ) |
Definition at line 350 of file rand.cc.
Referenced by BLI_hammersley_1d(), and BLI_hammersley_2d_sequence().
|
static |
Definition at line 221 of file rand.cc.
Referenced by BLI_thread_frand(), BLI_thread_rand(), and BLI_thread_srandom().