/************************************************************************
 * AUTHOR: NiuJiuRu
 * FILENAME: swrand.c
 * DESCRIPTION: 随机数产生函数
 * NOTE:
 * HISTORY:
 * 1, [2010-08-23] created by NiuJiuRu
 ************************************************************************/
#include "swapi.h"
#include "swrand.h"

/* 产生一个特定范围内的随机数, 并返回结果 */
unsigned int xrand32(unsigned int range)
{
  static __thread uint32_t seed = 0;

	if(seed == 0) seed = (uint32_t)time(NULL);
	if(seed == 0) seed = 2463534242u;

  seed ^= seed << 13;
  seed ^= seed >> 17;
  seed ^= seed << 5;

  if(range == 0) return seed;

  return seed % range;
}
