Chinaunix

标题: 取两个数间的随机数 [打印本页]

作者: 大隐隐于床    时间: 2009-07-22 23:45
标题: 取两个数间的随机数

unsigned int uiRandomBetweenAB( unsigned int A, unsigned int B)
{
     struct timeval t;
     gettimeofday( &t, NULL);
     srand( t.tv_usec);
     return (rand() % (A > B ? A-B : B-A)) + (A > B ? B : A);
}


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/91335/showart_2004010.html




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2