KiCad PCB EDA Suite
Loading...
Searching...
No Matches
3d_fastmath.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2016 Mario Luzeiro <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
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.
11 *
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.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
25
26
27#include "3d_fastmath.h"
28
29
30// Fast Float Random Numbers
31// a small and fast implementation for random float numbers in the range [-1,1]
32// References : Posted by dominik.ries[AT]gmail[DOT]com
33// http://www.musicdsp.org/showone.php?id=273
34
35
36// set the initial seed to whatever you like
37static int s_randSeed = 1;
38
39// fast rand float, using full 32bit precision
40// returns in the range [-1, 1] (not confirmed)
42{
43 s_randSeed *= 16807;
44
45 return (float)s_randSeed * 4.6566129e-010f;
46}
47
48
49// Fast rand, as described here:
50// http://wiki.osdev.org/Random_Number_Generator
51
52static unsigned long int s_nextRandSeed = 1;
53
54int Fast_rand( void ) // RAND_MAX assumed to be 32767
55{
56 s_nextRandSeed = s_nextRandSeed * 1103515245 + 12345;
57
58 return (unsigned int)(s_nextRandSeed >> 16) & 0x7FFF;
59}
60
61void Fast_srand( unsigned int seed )
62{
64}
float Fast_RandFloat()
static int s_randSeed
int Fast_rand(void)
static unsigned long int s_nextRandSeed
void Fast_srand(unsigned int seed)
Defines math related functions.
const uint32_t seed