| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- #pragma once
- class CRandomHelper
- {
- public:
- CRandomHelper();
- ~CRandomHelper();
- CRandomHelper(unsigned int seed)
- {
- next_seed = seed;
- }
- //生成0到1之间的随机数
- inline double lewaimai_rand()
- {
- return (double)myrand() / 0x7fff;
- }
- //生成范围内的随机整数
- inline int randInt(int begin, int end)
- {
- return begin + (myrand() % (end - begin + 1));
- }
- /* RAND_MAX assumed to be 32767 */
- inline int myrand(void)
- {
- next_seed = next_seed * 1103515245 + 12345;
- return((unsigned)(next_seed / 65536) % 32768);
- }
- inline void mysrand(unsigned int seed)
- {
- next_seed = seed;
- }
- private:
- unsigned long next_seed = 1;
- };
|