1
0

mptRandom.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * mptRandom.cpp
  3. * -------------
  4. * Purpose: PRNG
  5. * Notes : (currently none)
  6. * Authors: OpenMPT Devs
  7. * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
  8. */
  9. #include "stdafx.h"
  10. #include "mptRandom.h"
  11. OPENMPT_NAMESPACE_BEGIN
  12. namespace mpt
  13. {
  14. #if defined(MODPLUG_TRACKER) && !defined(MPT_BUILD_WINESUPPORT)
  15. static mpt::random_device *g_rd = nullptr;
  16. static mpt::thread_safe_prng<mpt::default_prng> *g_global_prng = nullptr;
  17. void set_global_random_device(mpt::random_device *rd)
  18. {
  19. g_rd = rd;
  20. }
  21. void set_global_prng(mpt::thread_safe_prng<mpt::default_prng> *prng)
  22. {
  23. g_global_prng = prng;
  24. }
  25. mpt::random_device & global_random_device()
  26. {
  27. return *g_rd;
  28. }
  29. mpt::thread_safe_prng<mpt::default_prng> & global_prng()
  30. {
  31. return *g_global_prng;
  32. }
  33. #else
  34. mpt::random_device & global_random_device()
  35. {
  36. static mpt::random_device g_rd;
  37. return g_rd;
  38. }
  39. mpt::thread_safe_prng<mpt::default_prng> & global_prng()
  40. {
  41. static mpt::thread_safe_prng<mpt::default_prng> g_global_prng(mpt::make_prng<mpt::default_prng>(global_random_device()));
  42. return g_global_prng;
  43. }
  44. #endif // MODPLUG_TRACKER && !MPT_BUILD_WINESUPPORT
  45. } // namespace mpt
  46. OPENMPT_NAMESPACE_END