Rand.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright (c) 2014, Oculus VR, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. */
  10. /// \file
  11. /// \brief \b [Internal] Random number generator
  12. ///
  13. #ifndef __RAND_H
  14. #define __RAND_H
  15. #include "Export.h"
  16. /// Initialise seed for Random Generator
  17. /// \note not threadSafe, use an instance of RakNetRandom if necessary per thread
  18. /// \param[in] seed The seed value for the random number generator.
  19. extern void RAK_DLL_EXPORT seedMT( unsigned int seed );
  20. /// \internal
  21. /// \note not threadSafe, use an instance of RakNetRandom if necessary per thread
  22. extern unsigned int RAK_DLL_EXPORT reloadMT( void );
  23. /// Gets a random unsigned int
  24. /// \note not threadSafe, use an instance of RakNetRandom if necessary per thread
  25. /// \return an integer random value.
  26. extern unsigned int RAK_DLL_EXPORT randomMT( void );
  27. /// Gets a random float
  28. /// \note not threadSafe, use an instance of RakNetRandom if necessary per thread
  29. /// \return 0 to 1.0f, inclusive
  30. extern float RAK_DLL_EXPORT frandomMT( void );
  31. /// Randomizes a buffer
  32. /// \note not threadSafe, use an instance of RakNetRandom if necessary per thread
  33. extern void RAK_DLL_EXPORT fillBufferMT( void *buffer, unsigned int bytes );
  34. namespace RakNet {
  35. // Same thing as above functions, but not global
  36. class RAK_DLL_EXPORT RakNetRandom
  37. {
  38. public:
  39. RakNetRandom();
  40. ~RakNetRandom();
  41. void SeedMT( unsigned int seed );
  42. unsigned int ReloadMT( void );
  43. unsigned int RandomMT( void );
  44. float FrandomMT( void );
  45. void FillBufferMT( void *buffer, unsigned int bytes );
  46. protected:
  47. unsigned int state[ 624 + 1 ];
  48. unsigned int *next;
  49. int left;
  50. };
  51. } // namespace RakNet
  52. #endif
粤ICP备19079148号