Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2013-04-16 03:12:40 +0400
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2013-04-16 03:12:40 +0400
commitafb4b65167165613f177a531bd3d4dcb3649c1c6 (patch)
tree32e1446b5fc3ce8ec00fa0e8b9e0fcb2eedda127 /source/blender/blenlib/BLI_rand.h
parent638b084f824bc345468bc8e02422b5da65a641a7 (diff)
Random number generator: replace a bunch of usage of the global random number
generator with a local one. It's not thread safe and will not give repeatable results, so in most cases it should not be used. Also fixes #34992 where the noise texture of a displacement modifier was not properly random in opengl animation render, because the seed got reset to a fixed value by an unrelated function while for final render it changed each frame.
Diffstat (limited to 'source/blender/blenlib/BLI_rand.h')
-rw-r--r--source/blender/blenlib/BLI_rand.h23
1 files changed, 7 insertions, 16 deletions
diff --git a/source/blender/blenlib/BLI_rand.h b/source/blender/blenlib/BLI_rand.h
index 3bc9a3bdb32..378beff3aa0 100644
--- a/source/blender/blenlib/BLI_rand.h
+++ b/source/blender/blenlib/BLI_rand.h
@@ -33,14 +33,15 @@
* \brief Random number functions.
*/
-/** RNG is just an abstract random number generator
- * type that avoids using globals, otherwise identical
- * to BLI_rand functions below.
+/* RNG is an abstract random number generator type that avoids using globals.
+ * Always use this instead of the global RNG unless you have a good reason,
+ * the global RNG is not thread safe and will not give repeatable results.
*/
struct RNG;
typedef struct RNG RNG;
struct RNG *BLI_rng_new(unsigned int seed);
+struct RNG *BLI_rng_new_srandom(unsigned int seed);
void BLI_rng_free(struct RNG *rng);
void BLI_rng_seed(struct RNG *rng, unsigned int seed);
@@ -53,27 +54,17 @@ void BLI_rng_shuffle_array(struct RNG *rng, void *data, int elemSize, int
/** Note that skipping is as slow as generating n numbers! */
void BLI_rng_skip(struct RNG *rng, int n);
-/** Seed the random number generator */
-void BLI_srand(unsigned int seed);
-
-/** Better seed for the random number generator, using noise.c hash[] */
+/** Seed for the random number generator, using noise.c hash[] */
void BLI_srandom(unsigned int seed);
/** Return a pseudo-random number N where 0<=N<(2^31) */
int BLI_rand(void);
-/** Return a pseudo-random number N where 0.0<=N<1.0 */
-double BLI_drand(void);
-
/** Return a pseudo-random number N where 0.0f<=N<1.0f */
float BLI_frand(void);
-/** Fills a block of memory starting at \a addr
- * and extending \a len bytes with pseudo-random
- * contents. This routine does not use nor modify
- * the state of the BLI random number generator.
- */
-void BLI_fillrand(void *addr, int len);
+/** Return a pseudo-random (hash) float from an integer value */
+float BLI_hash_frand(unsigned int seed);
/** Shuffle an array randomly using the given seed.
* contents. This routine does not use nor modify