Blender V2.61 - r43446
Classes | Defines | Typedefs | Functions | Variables

rand.c File Reference

#include <stdlib.h>
#include <string.h>
#include "MEM_guardedalloc.h"
#include "PIL_time.h"
#include "BLI_threads.h"
#include "BLI_rand.h"

Go to the source code of this file.

Classes

struct  RNG

Defines

#define MULTIPLIER   0x5DEECE66Dll
#define MASK   0x0000FFFFFFFFFFFFll
#define ADDEND   0xB
#define LOWSEED   0x330E

Typedefs

typedef unsigned long long r_uint64

Functions

RNGrng_new (unsigned int seed)
void rng_free (RNG *rng)
void rng_seed (RNG *rng, unsigned int seed)
void rng_srandom (RNG *rng, unsigned int seed)
int rng_getInt (RNG *rng)
double rng_getDouble (RNG *rng)
float rng_getFloat (RNG *rng)
void rng_shuffleArray (RNG *rng, void *data, int elemSize, int numElems)
void rng_skip (RNG *rng, int n)
void BLI_srand (unsigned int seed)
void BLI_srandom (unsigned int seed)
int BLI_rand (void)
double BLI_drand (void)
float BLI_frand (void)
void BLI_fillrand (void *addr, int len)
void BLI_array_randomize (void *data, int elemSize, int numElems, unsigned int seed)
void BLI_thread_srandom (int thread, unsigned int seed)
int BLI_thread_rand (int thread)
float BLI_thread_frand (int thread)

Variables

unsigned char hash []
static RNG theBLI_rng = {0}
static RNG rng_tab [BLENDER_MAX_THREADS]

Detailed Description

Definition in file rand.c.


Define Documentation

#define ADDEND   0xB

Definition at line 55 of file rand.c.

Referenced by rng_getInt().

#define LOWSEED   0x330E

Definition at line 57 of file rand.c.

Referenced by rng_seed().

#define MASK   0x0000FFFFFFFFFFFFll

Definition at line 52 of file rand.c.

Referenced by rng_getInt().

#define MULTIPLIER   0x5DEECE66Dll

Definition at line 51 of file rand.c.

Referenced by rng_getInt().


Typedef Documentation

typedef unsigned long long r_uint64

Definition at line 49 of file rand.c.


Function Documentation

void BLI_array_randomize ( void *  data,
int  elemSize,
int  numElems,
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 178 of file rand.c.

References rng_seed(), and rng_shuffleArray().

Referenced by applyModifier(), distribute_threads_init_data(), isb_add_samples(), and isb_add_samples_transp().

double BLI_drand ( void  )

Return a pseudo-random number N where 0.0<=N<1.0

Definition at line 159 of file rand.c.

References rng_getDouble().

Referenced by alter_co(), BLI_initjit(), hashvert_flag(), and RE_make_stars().

void BLI_fillrand ( void *  addr,
int  len 
)

Fills a block of memory starting at addr and extending len bytes with pseudo-random contents. This routine does not use nor modify the state of the BLI random number generator.

Definition at line 169 of file rand.c.

References p, PIL_check_seconds_timer(), rng_getInt(), and rng_seed().

float BLI_frand ( void  )
int BLI_rand ( void  )

Return a pseudo-random number N where 0<=N<(2^31)

Definition at line 154 of file rand.c.

References rng_getInt().

Referenced by calculatePropRatio(), defocus_blur(), new_particle_duplilist(), select_random_metaelems_exec(), selectrandom_curve(), selectrandom_mesh(), texnoise(), and weightvg_do_map().

void BLI_srand ( unsigned int  seed)
void BLI_srandom ( unsigned int  seed)
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 207 of file rand.c.

References rng_getFloat().

Referenced by give_jitter_plane(), QMC_initPixel(), sphere_sampler(), vol_get_transmittance(), and volumeintegrate().

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 202 of file rand.c.

References rng_getInt().

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 190 of file rand.c.

References BLENDER_MAX_THREADS, hash, rng_getInt(), and rng_seed().

Referenced by shadeDA_tile(), strand_shade_point(), zbufshade_sss_tile(), and zbufshade_tile().

void rng_free ( RNG rng)
double rng_getDouble ( RNG rng)

Definition at line 101 of file rand.c.

References rng_getInt().

Referenced by BLI_drand(), and hammersley_create().

float rng_getFloat ( RNG rng)
int rng_getInt ( RNG rng)
RNG* rng_new ( unsigned int  seed) [read]
void rng_seed ( RNG rng,
unsigned int  seed 
)

Definition at line 81 of file rand.c.

References LOWSEED, and RNG::X.

Referenced by BLI_array_randomize(), BLI_fillrand(), BLI_srand(), BLI_thread_srandom(), rng_new(), and rng_srandom().

void rng_shuffleArray ( RNG rng,
void *  data,
int  elemSize,
int  numElems 
)

Definition at line 111 of file rand.c.

References addon::engine::free(), i, and rng_getInt().

Referenced by BLI_array_randomize().

void rng_skip ( struct RNG rng,
int  n 
)

Note that skipping is as slow as generating n numbers!

Definition at line 130 of file rand.c.

References i, and rng_getInt().

Referenced by distribute_threads_exec(), and distribute_threads_exec_cb().

void rng_srandom ( RNG rng,
unsigned int  seed 
)

Definition at line 86 of file rand.c.

References hash, rng_getInt(), and rng_seed().

Referenced by BLI_srandom(), and precalculate_effector().


Variable Documentation

unsigned char hash[]
RNG rng_tab[BLENDER_MAX_THREADS] [static]

Definition at line 188 of file rand.c.

RNG theBLI_rng = {0} [static]

Definition at line 140 of file rand.c.