~diresu/blender/blender-command-port

« back to all changes in this revision

Viewing changes to source/blender/blenlib/BLI_rand.h

  • Committer: theeth
  • Date: 2008-10-14 16:52:04 UTC
  • Revision ID: vcs-imports@canonical.com-20081014165204-r32w2gm6s0osvdhn
copy back trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * @file BLI_rand.h
 
3
 * 
 
4
 * Random number functions.
 
5
 * $Id: BLI_rand.h 16168 2008-08-18 11:09:27Z genscher $
 
6
 *
 
7
 * ***** BEGIN GPL LICENSE BLOCK *****
 
8
 *
 
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.
 
13
 *
 
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.
 
18
 *
 
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.
 
22
 *
 
23
 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
 
24
 * All rights reserved.
 
25
 *
 
26
 * The Original Code is: all of this file.
 
27
 *
 
28
 * Contributor(s): none yet.
 
29
 *
 
30
 * ***** END GPL LICENSE BLOCK *****
 
31
 */
 
32
 
 
33
#ifndef BLI_RAND_H
 
34
#define BLI_RAND_H
 
35
 
 
36
        /* RNG is just an abstract random number generator
 
37
         * type that avoids using globals, otherwise identical
 
38
         * to BLI_rand functions below.
 
39
         */
 
40
struct RNG;
 
41
typedef struct RNG RNG;
 
42
 
 
43
struct RNG*     rng_new                 (unsigned int seed);
 
44
void            rng_free                (struct RNG* rng);
 
45
 
 
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);
 
52
 
 
53
        /** Note that skipping is as slow as generating n numbers! */
 
54
void            rng_skip                (struct RNG *rng, int n);
 
55
 
 
56
        /** Seed the random number generator */
 
57
void    BLI_srand               (unsigned int seed);
 
58
 
 
59
        /** Better seed for the random number generator, using noise.c hash[] */
 
60
void    BLI_srandom             (unsigned int seed);
 
61
 
 
62
        /** Return a pseudo-random number N where 0<=N<(2^31) */
 
63
int             BLI_rand                (void);
 
64
 
 
65
        /** Return a pseudo-random number N where 0.0<=N<1.0 */
 
66
double  BLI_drand               (void);
 
67
 
 
68
        /** Return a pseudo-random number N where 0.0f<=N<1.0f */
 
69
float   BLI_frand               (void);
 
70
 
 
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.
 
75
         */
 
76
void    BLI_fillrand    (void *addr, int len);
 
77
 
 
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.
 
81
         */
 
82
void    BLI_array_randomize     (void *data, int elemSize, int numElems, unsigned int seed);
 
83
 
 
84
 
 
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);
 
88
 
 
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);
 
92
 
 
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);
 
96
 
 
97
 
 
98
 
 
99
#endif
 
100