3 * Daniel Nelson - 8/24/0
5 * Copyright (C) 2000 Daniel Nelson
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 * Daniel Nelson - aluminumangel.org
39 /* static */ class Random
{
41 static void seed ( unsigned int seed
);
42 static unsigned int generateSeed ( );
43 static void initialize ( );
45 static inline bool chanceIn ( int chance
)
46 { return rand() % chance
== 0; }
48 // use then chance is a power of 2
49 static inline bool chanceIn2 ( int chance
)
50 { return (rand() & (chance
- 1)) == 0; }
52 static inline int number ( int maximum
)
53 { return rand() % maximum
; }
55 // use then maximum is a power of 2
56 static inline int number2 ( int maximum
)
57 { return rand() & (maximum
- 1); }
59 static inline float number ( )
60 { return rand() * (1.0 / (float) RAND_MAX
); }
62 static inline void angle ( float &x
, float &y
)
64 int n
= number2(GC_SIZE_RANDOM_ANGLE_TABLE
);
69 static inline void deathSparkAngle ( float &x
, float &y
)
71 int n
= number2(GC_SIZE_RANDOM_ANGLE_TABLE
);
72 x
= angle_death_spark_table
[n
].x
;
73 y
= angle_death_spark_table
[n
].y
;
76 static inline void celebrationSpark1Angle ( float &x
, float &y
)
78 int n
= number2(GC_SIZE_RANDOM_ANGLE_TABLE
);
79 x
= angle_celebration_spark_1_table
[n
].x
;
80 y
= angle_celebration_spark_1_table
[n
].y
;
83 static inline void celebrationSpark2Angle ( float &x
, float &y
)
85 int n
= number2(GC_SIZE_RANDOM_ANGLE_TABLE
);
86 x
= angle_celebration_spark_2_table
[n
].x
;
87 y
= angle_celebration_spark_2_table
[n
].y
;
91 static Angle angle_table
[GC_SIZE_RANDOM_ANGLE_TABLE
];
92 static Angle angle_death_spark_table
[GC_SIZE_RANDOM_ANGLE_TABLE
];
93 static Angle angle_celebration_spark_1_table
[GC_SIZE_RANDOM_ANGLE_TABLE
];
94 static Angle angle_celebration_spark_2_table
[GC_SIZE_RANDOM_ANGLE_TABLE
];