You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.0 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2016 Mario Luzeiro <mrluzeiro@ua.pt>
  5. * Copyright (C) 1992-2016 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, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. /**
  25. * @file 3d_fastmath.cpp
  26. * @brief
  27. */
  28. #include "3d_fastmath.h"
  29. // Fast Float Random Numbers
  30. // a small and fast implementation for random float numbers in the range [-1,1]
  31. // References : Posted by dominik.ries[AT]gmail[DOT]com
  32. // http://www.musicdsp.org/showone.php?id=273
  33. // set the initial seed to whatever you like
  34. static int s_randSeed = 1;
  35. // fast rand float, using full 32bit precision
  36. // returns in the range [-1, 1] (not confirmed)
  37. float Fast_RandFloat()
  38. {
  39. s_randSeed *= 16807;
  40. return (float)s_randSeed * 4.6566129e-010f;
  41. }
  42. // Fast rand, as described here:
  43. // http://wiki.osdev.org/Random_Number_Generator
  44. static unsigned long int s_nextRandSeed = 1;
  45. int Fast_rand( void ) // RAND_MAX assumed to be 32767
  46. {
  47. s_nextRandSeed = s_nextRandSeed * 1103515245 + 12345;
  48. return (unsigned int)(s_nextRandSeed >> 16) & 0x7FFF;
  49. }
  50. void Fast_srand( unsigned int seed )
  51. {
  52. s_nextRandSeed = seed;
  53. }