Blender  V3.3
rand.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2001-2002 NaN Holding BV. All rights reserved. */
3 
8 #include <cmath>
9 #include <cstdlib>
10 #include <cstring>
11 #include <ctime>
12 
13 #include "MEM_guardedalloc.h"
14 
15 #include "BLI_bitmap.h"
16 #include "BLI_math.h"
17 #include "BLI_rand.h"
18 #include "BLI_rand.hh"
19 #include "BLI_threads.h"
20 
21 /* defines BLI_INLINE */
22 #include "BLI_compiler_compat.h"
23 
24 #include "BLI_strict_flags.h"
25 #include "BLI_sys_types.h"
26 
27 extern "C" unsigned char BLI_noise_hash_uchar_512[512]; /* noise.c */
28 #define hash BLI_noise_hash_uchar_512
29 
33 struct RNG {
35 
36  MEM_CXX_CLASS_ALLOC_FUNCS("RNG")
37 };
38 
39 RNG *BLI_rng_new(unsigned int seed)
40 {
41  RNG *rng = new RNG();
42  rng->rng.seed(seed);
43  return rng;
44 }
45 
47 {
48  RNG *rng = new RNG();
49  rng->rng.seed_random(seed);
50  return rng;
51 }
52 
54 {
55  return new RNG(*rng);
56 }
57 
58 void BLI_rng_free(RNG *rng)
59 {
60  delete rng;
61 }
62 
63 void BLI_rng_seed(RNG *rng, unsigned int seed)
64 {
65  rng->rng.seed(seed);
66 }
67 
68 void BLI_rng_srandom(RNG *rng, unsigned int seed)
69 {
70  rng->rng.seed_random(seed);
71 }
72 
73 void BLI_rng_get_char_n(RNG *rng, char *bytes, size_t bytes_len)
74 {
75  rng->rng.get_bytes(blender::MutableSpan(bytes, static_cast<int64_t>(bytes_len)));
76 }
77 
79 {
80  return rng->rng.get_int32();
81 }
82 
83 unsigned int BLI_rng_get_uint(RNG *rng)
84 {
85  return rng->rng.get_uint32();
86 }
87 
88 double BLI_rng_get_double(RNG *rng)
89 {
90  return rng->rng.get_double();
91 }
92 
94 {
95  return rng->rng.get_float();
96 }
97 
98 void BLI_rng_get_float_unit_v2(RNG *rng, float v[2])
99 {
100  copy_v2_v2(v, rng->rng.get_unit_float2());
101 }
102 
103 void BLI_rng_get_float_unit_v3(RNG *rng, float v[3])
104 {
105  copy_v3_v3(v, rng->rng.get_unit_float3());
106 }
107 
109  RNG *rng, const float v1[2], const float v2[2], const float v3[2], float r_pt[2])
110 {
111  copy_v2_v2(r_pt, rng->rng.get_triangle_sample(v1, v2, v3));
112 }
113 
115  RNG *rng, const float v1[3], const float v2[3], const float v3[3], float r_pt[3])
116 {
117  copy_v3_v3(r_pt, rng->rng.get_triangle_sample_3d(v1, v2, v3));
118 }
119 
120 void BLI_rng_shuffle_array(RNG *rng, void *data, unsigned int elem_size_i, unsigned int elem_num)
121 {
122  if (elem_num <= 1) {
123  return;
124  }
125 
126  const uint elem_size = elem_size_i;
127  unsigned int i = elem_num;
128  void *temp = malloc(elem_size);
129 
130  while (i--) {
131  const unsigned int j = BLI_rng_get_uint(rng) % elem_num;
132  if (i != j) {
133  void *iElem = (unsigned char *)data + i * elem_size_i;
134  void *jElem = (unsigned char *)data + j * elem_size_i;
135  memcpy(temp, iElem, elem_size);
136  memcpy(iElem, jElem, elem_size);
137  memcpy(jElem, temp, elem_size);
138  }
139  }
140 
141  free(temp);
142 }
143 
144 void BLI_rng_shuffle_bitmap(struct RNG *rng, BLI_bitmap *bitmap, unsigned int bits_num)
145 {
146  if (bits_num <= 1) {
147  return;
148  }
149 
150  unsigned int i = bits_num;
151  while (i--) {
152  const unsigned int j = BLI_rng_get_uint(rng) % bits_num;
153  if (i != j) {
154  const bool i_bit = BLI_BITMAP_TEST(bitmap, i);
155  const bool j_bit = BLI_BITMAP_TEST(bitmap, j);
156  BLI_BITMAP_SET(bitmap, i, j_bit);
157  BLI_BITMAP_SET(bitmap, j, i_bit);
158  }
159  }
160 }
161 
162 void BLI_rng_skip(RNG *rng, int n)
163 {
164  rng->rng.skip((uint)n);
165 }
166 
167 /***/
168 
169 void BLI_array_frand(float *ar, int count, unsigned int seed)
170 {
171  RNG rng;
172 
173  BLI_rng_srandom(&rng, seed);
174 
175  for (int i = 0; i < count; i++) {
176  ar[i] = BLI_rng_get_float(&rng);
177  }
178 }
179 
180 float BLI_hash_frand(unsigned int seed)
181 {
182  RNG rng;
183 
184  BLI_rng_srandom(&rng, seed);
185  return BLI_rng_get_float(&rng);
186 }
187 
189  unsigned int elem_size,
190  unsigned int elem_num,
191  unsigned int seed)
192 {
193  RNG rng;
194 
195  BLI_rng_seed(&rng, seed);
196  BLI_rng_shuffle_array(&rng, data, elem_size, elem_num);
197 }
198 
199 void BLI_bitmap_randomize(BLI_bitmap *bitmap, unsigned int bits_num, unsigned int seed)
200 {
201  RNG rng;
202 
203  BLI_rng_seed(&rng, seed);
204  BLI_rng_shuffle_bitmap(&rng, bitmap, bits_num);
205 }
206 
207 /* ********* for threaded random ************** */
208 
210 
211 void BLI_thread_srandom(int thread, unsigned int seed)
212 {
213  if (thread >= BLENDER_MAX_THREADS) {
214  thread = 0;
215  }
216 
217  BLI_rng_seed(&rng_tab[thread], seed + hash[seed & 255]);
219  BLI_rng_seed(&rng_tab[thread], seed + hash[seed & 255]);
221  BLI_rng_seed(&rng_tab[thread], seed + hash[seed & 255]);
222 }
223 
225 {
226  return BLI_rng_get_int(&rng_tab[thread]);
227 }
228 
230 {
231  return BLI_rng_get_float(&rng_tab[thread]);
232 }
233 
236 };
237 
239 {
240  unsigned int i;
242  "random_array");
243 
244  for (i = 0; i < BLENDER_MAX_THREADS; i++) {
245  BLI_rng_srandom(&rngarr->rng_tab[i], (unsigned int)clock());
246  }
247 
248  return rngarr;
249 }
250 
252 {
253  MEM_freeN(rngarr);
254 }
255 
257 {
258  return BLI_rng_get_int(&rngarr->rng_tab[thread]);
259 }
260 
261 /* ********* Low-discrepancy sequences ************** */
262 
263 /* incremental halton sequence generator, from:
264  * "Instant Radiosity", Keller A. */
265 BLI_INLINE double halton_ex(double invprimes, double *offset)
266 {
267  double e = fabs((1.0 - *offset) - 1e-10);
268 
269  if (invprimes >= e) {
270  double lasth;
271  double h = invprimes;
272 
273  do {
274  lasth = h;
275  h *= invprimes;
276  } while (h >= e);
277 
278  *offset += ((lasth + h) - 1.0);
279  }
280  else {
281  *offset += invprimes;
282  }
283 
284  return *offset;
285 }
286 
287 void BLI_halton_1d(unsigned int prime, double offset, int n, double *r)
288 {
289  const double invprime = 1.0 / (double)prime;
290 
291  *r = 0.0;
292 
293  for (int s = 0; s < n; s++) {
294  *r = halton_ex(invprime, &offset);
295  }
296 }
297 
298 void BLI_halton_2d(const unsigned int prime[2], double offset[2], int n, double *r)
299 {
300  const double invprimes[2] = {1.0 / (double)prime[0], 1.0 / (double)prime[1]};
301 
302  r[0] = r[1] = 0.0;
303 
304  for (int s = 0; s < n; s++) {
305  for (int i = 0; i < 2; i++) {
306  r[i] = halton_ex(invprimes[i], &offset[i]);
307  }
308  }
309 }
310 
311 void BLI_halton_3d(const unsigned int prime[3], double offset[3], int n, double *r)
312 {
313  const double invprimes[3] = {
314  1.0 / (double)prime[0], 1.0 / (double)prime[1], 1.0 / (double)prime[2]};
315 
316  r[0] = r[1] = r[2] = 0.0;
317 
318  for (int s = 0; s < n; s++) {
319  for (int i = 0; i < 3; i++) {
320  r[i] = halton_ex(invprimes[i], &offset[i]);
321  }
322  }
323 }
324 
325 void BLI_halton_2d_sequence(const unsigned int prime[2], double offset[2], int n, double *r)
326 {
327  const double invprimes[2] = {1.0 / (double)prime[0], 1.0 / (double)prime[1]};
328 
329  for (int s = 0; s < n; s++) {
330  for (int i = 0; i < 2; i++) {
331  r[s * 2 + i] = halton_ex(invprimes[i], &offset[i]);
332  }
333  }
334 }
335 
336 /* From "Sampling with Hammersley and Halton Points" TT Wong
337  * Appendix: Source Code 1 */
338 BLI_INLINE double radical_inverse(unsigned int n)
339 {
340  double u = 0;
341 
342  /* This reverse the bit-wise representation
343  * around the decimal point. */
344  for (double p = 0.5; n; p *= 0.5, n >>= 1) {
345  if (n & 1) {
346  u += p;
347  }
348  }
349 
350  return u;
351 }
352 
353 void BLI_hammersley_1d(unsigned int n, double *r)
354 {
355  *r = radical_inverse(n);
356 }
357 
358 void BLI_hammersley_2d_sequence(unsigned int n, double *r)
359 {
360  for (unsigned int s = 0; s < n; s++) {
361  r[s * 2 + 0] = (double)(s + 0.5) / (double)n;
362  r[s * 2 + 1] = radical_inverse(s);
363  }
364 }
365 
366 namespace blender {
367 
369 {
370  this->seed(seed + hash[seed & 255]);
371  seed = this->get_uint32();
372  this->seed(seed + hash[seed & 255]);
373  seed = this->get_uint32();
374  this->seed(seed + hash[seed & 255]);
375 }
376 
378 {
379  /* Support for negative values can be added when necessary. */
380  BLI_assert(x >= 0.0f);
381  const float round_up_probability = fractf(x);
382  const bool round_up = round_up_probability > this->get_float();
383  return (int)x + (int)round_up;
384 }
385 
387 {
388  float a = (float)(M_PI * 2.0) * this->get_float();
389  return {cosf(a), sinf(a)};
390 }
391 
393 {
394  float z = (2.0f * this->get_float()) - 1.0f;
395  float r = 1.0f - z * z;
396  if (r > 0.0f) {
397  float a = (float)(M_PI * 2.0) * this->get_float();
398  r = sqrtf(r);
399  float x = r * cosf(a);
400  float y = r * sinf(a);
401  return {x, y, z};
402  }
403  return {0.0f, 0.0f, 1.0f};
404 }
405 
407 {
408  float u = this->get_float();
409  float v = this->get_float();
410 
411  if (u + v > 1.0f) {
412  u = 1.0f - u;
413  v = 1.0f - v;
414  }
415 
416  float2 side_u = v2 - v1;
417  float2 side_v = v3 - v1;
418 
419  float2 sample = v1;
420  sample += side_u * u;
421  sample += side_v * v;
422  return sample;
423 }
424 
426 {
427  float u = this->get_float();
428  float v = this->get_float();
429 
430  if (u + v > 1.0f) {
431  u = 1.0f - u;
432  v = 1.0f - v;
433  }
434 
435  float3 side_u = v2 - v1;
436  float3 side_v = v3 - v1;
437 
438  float3 sample = v1;
439  sample += side_u * u;
440  sample += side_v * v;
441  return sample;
442 }
443 
445 {
446  constexpr int64_t mask_bytes = 2;
447  constexpr int64_t rand_stride = static_cast<int64_t>(sizeof(x_)) - mask_bytes;
448 
449  int64_t last_len = 0;
450  int64_t trim_len = r_bytes.size();
451 
452  if (trim_len > rand_stride) {
453  last_len = trim_len % rand_stride;
454  trim_len = trim_len - last_len;
455  }
456  else {
457  trim_len = 0;
458  last_len = r_bytes.size();
459  }
460 
461  const char *data_src = (const char *)&x_;
462  int64_t i = 0;
463  while (i != trim_len) {
464  BLI_assert(i < trim_len);
465 #ifdef __BIG_ENDIAN__
466  for (int64_t j = (rand_stride + mask_bytes) - 1; j != mask_bytes - 1; j--)
467 #else
468  for (int64_t j = 0; j != rand_stride; j++)
469 #endif
470  {
471  r_bytes[i++] = data_src[j];
472  }
473  this->step();
474  }
475  if (last_len) {
476  for (int64_t j = 0; j != last_len; j++) {
477  r_bytes[i++] = data_src[j];
478  }
479  }
480 }
481 
482 } // namespace blender
typedef float(TangentPoint)[2]
#define BLI_assert(a)
Definition: BLI_assert.h:46
#define BLI_BITMAP_TEST(_bitmap, _index)
Definition: BLI_bitmap.h:64
#define BLI_BITMAP_SET(_bitmap, _index, _set)
Definition: BLI_bitmap.h:102
unsigned int BLI_bitmap
Definition: BLI_bitmap.h:16
#define BLI_INLINE
void BLI_kdtree_nd_() free(KDTree *tree)
Definition: kdtree_impl.h:102
#define M_PI
Definition: BLI_math_base.h:20
MINLINE void copy_v2_v2(float r[2], const float a[2])
MINLINE void copy_v3_v3(float r[3], const float a[3])
Random number functions.
struct RNG RNG
Definition: BLI_rand.h:24
Strict compiler flags for areas of code we want to ensure don't do conversions without us knowing abo...
unsigned int uint
Definition: BLI_sys_types.h:67
#define BLENDER_MAX_THREADS
Definition: BLI_threads.h:19
typedef double(DMatrix)[4][4]
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble z
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble GLdouble r _GL_VOID_RET _GL_VOID GLfloat GLfloat r _GL_VOID_RET _GL_VOID GLint GLint r _GL_VOID_RET _GL_VOID GLshort GLshort r _GL_VOID_RET _GL_VOID GLdouble GLdouble r
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble v1
Read Guarded memory(de)allocation.
ATTR_WARN_UNUSED_RESULT const BMVert * v2
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
ATTR_WARN_UNUSED_RESULT const BMVert * v
static unsigned long seed
Definition: btSoftBody.h:39
constexpr int64_t size() const
Definition: BLI_span.hh:511
void get_bytes(MutableSpan< char > r_bytes)
Definition: rand.cc:444
int round_probabilistic(float x)
Definition: rand.cc:377
void seed_random(uint32_t seed)
Definition: rand.cc:368
float3 get_triangle_sample_3d(float3 v1, float3 v2, float3 v3)
Definition: rand.cc:425
float2 get_triangle_sample(float2 v1, float2 v2, float2 v3)
Definition: rand.cc:406
void seed(uint32_t seed)
Definition: BLI_rand.hh:29
Definition: thread.h:34
#define sinf(x)
Definition: cuda/compat.h:102
#define cosf(x)
Definition: cuda/compat.h:101
int count
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:33
MINLINE float fractf(float a)
ccl_device_inline float2 fabs(const float2 &a)
Definition: math_float2.h:222
#define sqrtf(x)
Definition: metal/compat.h:243
static unsigned a[3]
Definition: RandGen.cpp:78
RNG_THREAD_ARRAY * BLI_rng_threaded_new()
Definition: rand.cc:238
void BLI_rng_shuffle_bitmap(struct RNG *rng, BLI_bitmap *bitmap, unsigned int bits_num)
Definition: rand.cc:144
float BLI_rng_get_float(RNG *rng)
Definition: rand.cc:93
void BLI_rng_free(RNG *rng)
Definition: rand.cc:58
float BLI_thread_frand(int thread)
Definition: rand.cc:229
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: rand.cc:114
void BLI_hammersley_1d(unsigned int n, double *r)
Definition: rand.cc:353
RNG * BLI_rng_copy(RNG *rng)
Definition: rand.cc:53
int BLI_rng_get_int(RNG *rng)
Definition: rand.cc:78
int BLI_thread_rand(int thread)
Definition: rand.cc:224
BLI_INLINE double radical_inverse(unsigned int n)
Definition: rand.cc:338
#define hash
Definition: rand.cc:28
void BLI_rng_get_float_unit_v3(RNG *rng, float v[3])
Definition: rand.cc:103
void BLI_halton_2d_sequence(const unsigned int prime[2], double offset[2], int n, double *r)
Definition: rand.cc:325
void BLI_bitmap_randomize(BLI_bitmap *bitmap, unsigned int bits_num, unsigned int seed)
Definition: rand.cc:199
float BLI_hash_frand(unsigned int seed)
Definition: rand.cc:180
void BLI_halton_3d(const unsigned int prime[3], double offset[3], int n, double *r)
Definition: rand.cc:311
void BLI_rng_threaded_free(struct RNG_THREAD_ARRAY *rngarr)
Definition: rand.cc:251
static RNG rng_tab[BLENDER_MAX_THREADS]
Definition: rand.cc:209
int BLI_rng_thread_rand(RNG_THREAD_ARRAY *rngarr, int thread)
Definition: rand.cc:256
void BLI_rng_srandom(RNG *rng, unsigned int seed)
Definition: rand.cc:68
void BLI_halton_2d(const unsigned int prime[2], double offset[2], int n, double *r)
Definition: rand.cc:298
void BLI_rng_get_char_n(RNG *rng, char *bytes, size_t bytes_len)
Definition: rand.cc:73
double BLI_rng_get_double(RNG *rng)
Definition: rand.cc:88
void BLI_rng_shuffle_array(RNG *rng, void *data, unsigned int elem_size_i, unsigned int elem_num)
Definition: rand.cc:120
void BLI_rng_skip(RNG *rng, int n)
Definition: rand.cc:162
RNG * BLI_rng_new_srandom(unsigned int seed)
Definition: rand.cc:46
void BLI_thread_srandom(int thread, unsigned int seed)
Definition: rand.cc:211
unsigned int BLI_rng_get_uint(RNG *rng)
Definition: rand.cc:83
RNG * BLI_rng_new(unsigned int seed)
Definition: rand.cc:39
void BLI_array_randomize(void *data, unsigned int elem_size, unsigned int elem_num, unsigned int seed)
Definition: rand.cc:188
void BLI_rng_seed(RNG *rng, unsigned int seed)
Definition: rand.cc:63
void BLI_rng_get_float_unit_v2(RNG *rng, float v[2])
Definition: rand.cc:98
void BLI_halton_1d(unsigned int prime, double offset, int n, double *r)
Definition: rand.cc:287
BLI_INLINE double halton_ex(double invprimes, double *offset)
Definition: rand.cc:265
unsigned char BLI_noise_hash_uchar_512[512]
Definition: rand.cc:27
void BLI_array_frand(float *ar, int count, unsigned int seed)
Definition: rand.cc:169
void BLI_hammersley_2d_sequence(unsigned int n, double *r)
Definition: rand.cc:358
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])
Definition: rand.cc:108
unsigned int uint32_t
Definition: stdint.h:80
__int64 int64_t
Definition: stdint.h:89
RNG rng_tab[BLENDER_MAX_THREADS]
Definition: rand.cc:235
Definition: rand.cc:33
blender::RandomNumberGenerator rng
Definition: rand.cc:34
ccl_device_inline size_t round_up(size_t x, size_t multiple)
Definition: util/types.h:56