4
* Random number functions.
5
* $Id: BLI_rand.h 16168 2008-08-18 11:09:27Z genscher $
7
* ***** BEGIN GPL LICENSE BLOCK *****
9
* This program is free software; you can redistribute it and/or
10
* modify it under the terms of the GNU General Public License
11
* as published by the Free Software Foundation; either version 2
12
* of the License, or (at your option) any later version.
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this program; if not, write to the Free Software Foundation,
21
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24
* All rights reserved.
26
* The Original Code is: all of this file.
28
* Contributor(s): none yet.
30
* ***** END GPL LICENSE BLOCK *****
36
/* RNG is just an abstract random number generator
37
* type that avoids using globals, otherwise identical
38
* to BLI_rand functions below.
41
typedef struct RNG RNG;
43
struct RNG* rng_new (unsigned int seed);
44
void rng_free (struct RNG* rng);
46
void rng_seed (struct RNG* rng, unsigned int seed);
47
void rng_srandom(struct RNG *rng, unsigned int seed);
48
int rng_getInt (struct RNG* rng);
49
double rng_getDouble (struct RNG* rng);
50
float rng_getFloat (struct RNG* rng);
51
void rng_shuffleArray(struct RNG *rng, void *data, int elemSize, int numElems);
53
/** Note that skipping is as slow as generating n numbers! */
54
void rng_skip (struct RNG *rng, int n);
56
/** Seed the random number generator */
57
void BLI_srand (unsigned int seed);
59
/** Better seed for the random number generator, using noise.c hash[] */
60
void BLI_srandom (unsigned int seed);
62
/** Return a pseudo-random number N where 0<=N<(2^31) */
65
/** Return a pseudo-random number N where 0.0<=N<1.0 */
66
double BLI_drand (void);
68
/** Return a pseudo-random number N where 0.0f<=N<1.0f */
69
float BLI_frand (void);
71
/** Fills a block of memory starting at @a addr
72
* and extending @a len bytes with pseudo-random
73
* contents. This routine does not use nor modify
74
* the state of the BLI random number generator.
76
void BLI_fillrand (void *addr, int len);
78
/** Shuffle an array randomly using the given seed.
79
* contents. This routine does not use nor modify
80
* the state of the BLI random number generator.
82
void BLI_array_randomize (void *data, int elemSize, int numElems, unsigned int seed);
85
/** Better seed for the random number generator, using noise.c hash[] */
86
/** Allows up to 16 threads to address */
87
void BLI_thread_srandom (int thread, unsigned int seed);
89
/** Return a pseudo-random number N where 0<=N<(2^31) */
90
/** Allows up to 16 threads to address */
91
int BLI_thread_rand (int thread);
93
/** Return a pseudo-random number N where 0.0f<=N<1.0f */
94
/** Allows up to 16 threads to address */
95
float BLI_thread_frand (int thread);