兰德实施 [英] Rand Implementation

查看:116
本文介绍了兰德实施的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过怎样兰特()和srand()函数功能的实现,想捏捏code到其修改为我的要求。在哪里可以找到兰特源$ C ​​$ C()和srand()函数。

I would like to go through how rand() and srand() functions are implemented and would like to tweak the code to modify it to my requirements. Where can i find the source code of rand() and srand().

推荐答案

这需要种子作为输入参数,通常喜欢如下: -

It takes a seed as in input argument, usually like follows:-

double result = srand(time(NULL));

和返回附着的可能性和发生的,因此预期数的随机数。

and returns a random number that adheres to the probability and hence expected number of occurrences.

通过 codeGuru论坛: -

void __cdecl srand (unsigned int seed)
{
    #ifdef _MT
        _getptd()->_holdrand = (unsigned long)seed;
    #else /* _MT */
        holdrand = (long)seed;
    #endif /* _MT */
}

int __cdecl rand (void)
{
   #ifdef _MT
    _ptiddata ptd = _getptd();
    return( ((ptd->_holdrand = ptd->_holdrand * 214013L + 2531011L) >> 16) &
    0x7fff );
   #else /* _MT */
    return(((holdrand = holdrand * 214013L + 2531011L) >> 16) & 0x7fff);
   #endif /* _MT */
}

希望这有助于。

这篇关于兰德实施的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆