Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7563357
  • 博文数量: 961
  • 博客积分: 15795
  • 博客等级: 上将
  • 技术积分: 16612
  • 用 户 组: 普通用户
  • 注册时间: 2010-08-07 14:23
文章分类

全部博文(961)

文章存档

2016年(1)

2015年(61)

2014年(41)

2013年(51)

2012年(235)

2011年(391)

2010年(181)

分类: 嵌入式

2012-11-02 14:19:11

/**

 * 模块功能:随机数等相关的接口

* Greate Data:2012.11.01

 */

#include

#include

#include

#include

 

/**

 * 函数功能:获取指定长度的随机数

 * uiLen( 入口):<= 4096!=0,要获取的随机数长度

 *  *pvRandom( 出口):不能为空,获取到的随机数指针

 *  返回值:0x00-->成功 :0x8B-->参错错误 :0x01-->失败

 */

int ST_GetRandom(unsigned int uiLen, int *pvRandom)

{

       if (uiLen > 4096 || uiLen < 1)

              return 0x8b;

      

       int i;

       printf("get random\n");

       unsigned long long tick;

       int seed;

       struct timeval tm;

      

       for (i = 0; i < uiLen;i++)

       {

              gettimeofday(&tm, NULL);

              tick = tm.tv_usec;

              seed =(tick);

              srandom(seed);

              *(pvRandom+i)=(unsigned char)random();

              printf("random=%d\n",(unsigned char)random());

       }

       return 0;

}

 

 

阅读(1422) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~