Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
951 B

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=====================================================================================//
  6. #include <halton.h>
  7. // NOTE: This has to be the last file included!
  8. #include "tier0/memdbgon.h"
  9. HaltonSequenceGenerator_t::HaltonSequenceGenerator_t(int b)
  10. {
  11. base=b;
  12. fbase=(float) b;
  13. seed=1;
  14. }
  15. float HaltonSequenceGenerator_t::GetElement(int elem)
  16. {
  17. int tmpseed=seed;
  18. float ret=0.0;
  19. float base_inv=1.0/fbase;
  20. while(tmpseed)
  21. {
  22. int dig=tmpseed % base;
  23. ret+=((float) dig)*base_inv;
  24. base_inv/=fbase;
  25. tmpseed/=base;
  26. }
  27. return ret;
  28. }
  29. int InsideOut( int nTotal, int nCounter )
  30. {
  31. int b = 0;
  32. for ( int m = nTotal, k = 1; k < nTotal; k <<= 1 )
  33. {
  34. if ( nCounter << 1 >= m )
  35. {
  36. b += k;
  37. nCounter -= ( m + 1 ) >> 1;
  38. m >>= 1;
  39. }
  40. else
  41. {
  42. m = ( m + 1 ) >> 1;
  43. }
  44. }
  45. Assert( ( b >= 0 ) && ( b < nTotal ) );
  46. return b;
  47. }