• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Goom Project
2  * Copyright (C) <2003> iOS-Software
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 #ifndef _GOOMTOOLS_H
20 #define _GOOMTOOLS_H
21 
22 #include "goom_config.h"
23 
24 /*
25  * Random number generator wrapper for faster random number.
26  */
27 
28 #define GOOM_NB_RAND 0x10000
29 
30 typedef struct _GOOM_RANDOM {
31 	int array[GOOM_NB_RAND];
32 	unsigned short pos;
33 } GoomRandom;
34 
35 GoomRandom *goom_random_init(int i);
36 void goom_random_free(GoomRandom *grandom);
37 
goom_random(GoomRandom * grandom)38 inline static int goom_random(GoomRandom *grandom) {
39 
40 	grandom->pos++; /* works because pos is an unsigned short */
41 	return grandom->array[grandom->pos];
42 }
43 
goom_irand(GoomRandom * grandom,int i)44 inline static int goom_irand(GoomRandom *grandom, int i) {
45 
46 	grandom->pos++;
47 	return grandom->array[grandom->pos] % i;
48 }
49 
50 /* called to change the specified number of value in the array, so that the array does not remain the same*/
51 void goom_random_update_array(GoomRandom *grandom, int numberOfValuesToChange);
52 
53 #endif
54