2011-02-18 13:58:08 +00:00
|
|
|
/*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
2008-04-16 22:40:48 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
|
|
|
|
2012-02-17 18:59:41 +00:00
|
|
|
#ifndef __BLI_RAND_H__
|
|
|
|
#define __BLI_RAND_H__
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2011-02-18 13:58:08 +00:00
|
|
|
/** \file BLI_rand.h
|
|
|
|
* \ingroup bli
|
|
|
|
* \brief Random number functions.
|
|
|
|
*/
|
|
|
|
|
2013-04-15 23:12:40 +00:00
|
|
|
/* 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.
|
2011-02-18 13:58:08 +00:00
|
|
|
*/
|
2005-07-25 20:33:10 +00:00
|
|
|
struct RNG;
|
2005-07-25 20:56:48 +00:00
|
|
|
typedef struct RNG RNG;
|
2005-07-25 20:33:10 +00:00
|
|
|
|
2012-10-23 13:50:44 +00:00
|
|
|
struct RNG *BLI_rng_new(unsigned int seed);
|
2013-04-15 23:12:40 +00:00
|
|
|
struct RNG *BLI_rng_new_srandom(unsigned int seed);
|
2014-07-17 18:56:13 +10:00
|
|
|
void BLI_rng_free(struct RNG *rng) ATTR_NONNULL(1);
|
2005-07-25 20:33:10 +00:00
|
|
|
|
2014-07-17 18:56:13 +10:00
|
|
|
void BLI_rng_seed(struct RNG *rng, unsigned int seed) ATTR_NONNULL(1);
|
|
|
|
void BLI_rng_srandom(struct RNG *rng, unsigned int seed) ATTR_NONNULL(1);
|
|
|
|
int BLI_rng_get_int(struct RNG *rng) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
|
|
|
|
unsigned int BLI_rng_get_uint(struct RNG *rng) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
|
|
|
|
double BLI_rng_get_double(struct RNG *rng) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
|
|
|
|
float BLI_rng_get_float(struct RNG *rng) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
|
|
|
|
void BLI_rng_get_float_unit_v2(struct RNG *rng, float v[2]) ATTR_NONNULL(1, 2);
|
|
|
|
void BLI_rng_get_float_unit_v3(struct RNG *rng, float v[3]) ATTR_NONNULL(1, 2);
|
|
|
|
void BLI_rng_shuffle_array(struct RNG *rng, void *data, unsigned int elem_size_i, unsigned int elem_tot) ATTR_NONNULL(1, 2);
|
2005-07-25 20:33:10 +00:00
|
|
|
|
2012-05-12 20:39:39 +00:00
|
|
|
/** Note that skipping is as slow as generating n numbers! */
|
2014-07-17 18:56:13 +10:00
|
|
|
void BLI_rng_skip(struct RNG *rng, int n) ATTR_NONNULL(1);
|
2007-12-04 13:57:28 +00:00
|
|
|
|
2013-04-15 23:12:40 +00:00
|
|
|
/** Seed for the random number generator, using noise.c hash[] */
|
2012-05-12 20:39:39 +00:00
|
|
|
void BLI_srandom(unsigned int seed);
|
2005-08-25 13:11:04 +00:00
|
|
|
|
2012-05-12 20:39:39 +00:00
|
|
|
/** Return a pseudo-random number N where 0<=N<(2^31) */
|
2014-07-17 18:56:13 +10:00
|
|
|
int BLI_rand(void) ATTR_WARN_UNUSED_RESULT;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-12 20:39:39 +00:00
|
|
|
/** Return a pseudo-random number N where 0.0f<=N<1.0f */
|
2014-07-17 18:56:13 +10:00
|
|
|
float BLI_frand(void) ATTR_WARN_UNUSED_RESULT;
|
2014-03-30 13:03:57 +11:00
|
|
|
void BLI_frand_unit_v3(float v[3]);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2013-04-15 23:12:40 +00:00
|
|
|
/** Return a pseudo-random (hash) float from an integer value */
|
2014-07-17 18:56:13 +10:00
|
|
|
float BLI_hash_frand(unsigned int seed) ATTR_WARN_UNUSED_RESULT;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-12 20:39:39 +00:00
|
|
|
/** Shuffle an array randomly using the given seed.
|
|
|
|
* contents. This routine does not use nor modify
|
|
|
|
* the state of the BLI random number generator.
|
|
|
|
*/
|
2014-03-30 20:35:59 +11:00
|
|
|
void BLI_array_randomize(void *data, unsigned int elem_size, unsigned int elem_tot, unsigned int seed);
|
2005-07-20 03:33:44 +00:00
|
|
|
|
2005-08-25 13:11:04 +00:00
|
|
|
|
2012-05-12 20:39:39 +00:00
|
|
|
/** Better seed for the random number generator, using noise.c hash[] */
|
|
|
|
/** Allows up to BLENDER_MAX_THREADS threads to address */
|
|
|
|
void BLI_thread_srandom(int thread, unsigned int seed);
|
2005-08-25 13:11:04 +00:00
|
|
|
|
2012-05-12 20:39:39 +00:00
|
|
|
/** Return a pseudo-random number N where 0<=N<(2^31) */
|
|
|
|
/** Allows up to BLENDER_MAX_THREADS threads to address */
|
2014-07-17 18:56:13 +10:00
|
|
|
int BLI_thread_rand(int thread) ATTR_WARN_UNUSED_RESULT;
|
2005-08-25 13:11:04 +00:00
|
|
|
|
2012-05-12 20:39:39 +00:00
|
|
|
/** Return a pseudo-random number N where 0.0f<=N<1.0f */
|
|
|
|
/** Allows up to BLENDER_MAX_THREADS threads to address */
|
2014-07-17 18:56:13 +10:00
|
|
|
float BLI_thread_frand(int thread) ATTR_WARN_UNUSED_RESULT;
|
2005-08-25 13:11:04 +00:00
|
|
|
|
2012-10-23 13:50:44 +00:00
|
|
|
#endif /* __BLI_RAND_H__ */
|