gA6ri3l
驱动牛犊
驱动牛犊
  • 注册日期2007-04-04
  • 最后登录2007-07-03
  • 粉丝0
  • 关注0
  • 积分100分
  • 威望11点
  • 贡献值0点
  • 好评度10点
  • 原创分0分
  • 专家分0分
阅读:3152回复:2

请问在驱动中如何产生随机数?

楼主#
更多 发布于:2007-06-13 22:44
因为在驱动中不能调用Time()
rand()
不知道怎么产生随机数呢?
wht0395
驱动小牛
驱动小牛
  • 注册日期2006-07-06
  • 最后登录2009-06-10
  • 粉丝0
  • 关注0
  • 积分583分
  • 威望135点
  • 贡献值0点
  • 好评度122点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2007-06-14 03:13
产生的数随机程度我不知道怎么样
你试试


struct Rand_Context
{
    int Seed;
};

unsigned long InitRand (struct Rand_Context *pContext,signed int seed)
{
    pContext->Seed=(unsigned long)seed;
    return pContext->Seed;
}

int random(struct Rand_Context *pContext,int min,int max)
{
    int Result=( ( ((pContext->Seed) = (pContext->Seed) * 214013L+ 2531011L) >> 16) & 0x7fff );
    Result= Result /(0x7fff/max)+min;
    while(Result>max||Result<min)
    {
        Result=( ( ((pContext->Seed) = (pContext->Seed) * 214013L+ 2531011L) >> 16) & 0x7fff );
        Result= Result /(0x7fff/max)+min;
    }
    return Result;
}
什么不懂的学生
rayyang2000
管理员
管理员
  • 注册日期2001-03-23
  • 最后登录2012-09-13
  • 粉丝3
  • 关注0
  • 积分1036分
  • 威望925点
  • 贡献值3点
  • 好评度823点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2007-06-14 08:30
补充:用KeQuerySystemTime拿时间
天天coding-debugging中----超稀饭memory dump file ======================================================== [b]Windows Device Driver Development and Consulting Service[/b] [color=blue][url]http://www.ybwork.com[/url][/color] ========================================================
游客

返回顶部