Random.h 877 B

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include "BaseTypes.h"
  10. #include "LCGRandom.h"
  11. namespace CryRandom_Internal
  12. {
  13. // Private access point to the global random number generator.
  14. extern CRndGen g_random_generator;
  15. }
  16. inline uint32 cry_random_uint32()
  17. {
  18. return CryRandom_Internal::g_random_generator.GenerateUint32();
  19. }
  20. // Ranged function returns random value within the *inclusive* range
  21. // between minValue and maxValue.
  22. // Any orderings work correctly: minValue <= maxValue and
  23. // minValue >= minValue.
  24. template <class T>
  25. inline T cry_random(const T minValue, const T maxValue)
  26. {
  27. return CryRandom_Internal::g_random_generator.GetRandom(minValue, maxValue);
  28. }