random.cpp
上传用户:jnfxsk
上传日期:2022-06-16
资源大小:3675k
文件大小:1k
源码类别:

游戏引擎

开发平台:

Visual C++

  1. /*
  2. ** Haaf's Game Engine 1.8
  3. ** Copyright (C) 2003-2007, Relish Games
  4. ** hge.relishgames.com
  5. **
  6. ** Core functions implementation: random number generation
  7. */
  8. #include "hge_impl.h"
  9. unsigned int g_seed=0;
  10. void CALL HGE_Impl::Random_Seed(int seed)
  11. {
  12. if(!seed) g_seed=timeGetTime();
  13. else g_seed=seed;
  14. }
  15. int CALL HGE_Impl::Random_Int(int min, int max)
  16. {
  17. g_seed=214013*g_seed+2531011;
  18. return min+(g_seed ^ g_seed>>15)%(max-min+1);
  19. }
  20. float CALL HGE_Impl::Random_Float(float min, float max)
  21. {
  22. g_seed=214013*g_seed+2531011;
  23. //return min+g_seed*(1.0f/4294967295.0f)*(max-min);
  24. return min+(g_seed>>16)*(1.0f/65535.0f)*(max-min);
  25. }