Random.cpp 636 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #include "../Precompiled.h"
  4. #include "../Math/Random.h"
  5. #include "../DebugNew.h"
  6. namespace Urho3D
  7. {
  8. static unsigned randomSeed = 1;
  9. void SetRandomSeed(unsigned seed)
  10. {
  11. randomSeed = seed;
  12. }
  13. unsigned GetRandomSeed()
  14. {
  15. return randomSeed;
  16. }
  17. int Rand()
  18. {
  19. randomSeed = randomSeed * 214013 + 2531011;
  20. return (randomSeed >> 16u) & 32767u;
  21. }
  22. float RandStandardNormal()
  23. {
  24. float val = 0.0f;
  25. for (int i = 0; i < 12; i++)
  26. val += Rand() / 32768.0f;
  27. val -= 6.0f;
  28. // Now val is approximatly standard normal distributed
  29. return val;
  30. }
  31. }