论坛: 编程破解 标题: VC中的rand()的计算公式和参数是什么? 复制本贴地址    
作者: ProgramLive [coolcall]    论坛用户   登录
我想推算rand()的下个数值,但不会看库代码

地主 发表时间: 06-04-23 12:55

回复: 286 [unique]   版主   登录
#include <stdlib.h>
#include <stdio.h>
#include <time.h>

void main( void )
{
  int i;

  /* Seed the random-number generator with current time so that
    * the numbers will be different every time we run.
    */
  srand( (unsigned)time( NULL ) );

  /* Display 10 numbers. */
  for( i = 0;  i < 10;i++ )
      printf( "  %6d\n", rand() );
}

算法不同库算法也不同,但都是伪随机数。

B1层 发表时间: 06-04-27 17:45

回复: ProgramLive [coolcall]   论坛用户   登录
你可能误会我意思了
比如说:

  srand( 1 );//这我设置成固定数值;

  for( i = 0;  i < 3;i++ )
      printf( "  %6d\n", rand()%10 );


假如运行结果为:
      i=0 rand=5;
      i=1 rand=6;
      i=2 rand=4;
那随意找的i=3 rand=等于多少我想自己推算出来,我想知道VC中的rand()真正算法


[此贴被 ProgramLive(coolcall) 在 04月29日18时43分 编辑过]

B2层 发表时间: 06-04-29 18:42

回复: 286 [unique]   版主   登录
伪随机数生成算法吗。谁去研究这个,一般可能是采用多项式乘法的方法产生。
不同编译器产生算法肯定不同的。

B3层 发表时间: 06-04-30 09:23

论坛: 编程破解

20CN网络安全小组版权所有
Copyright © 2000-2010 20CN Security Group. All Rights Reserved.
论坛程序编写:NetDemon

粤ICP备05087286号