请问如何生成一个0,1的随机数和0~5之间的随机数???

解决方案 »

  1.   

    要生成某个范围的随机数,只要对范围取模就可以了
    Rand()%9
    好象是这样的,我看看
      

  2.   

    Rand小写
    应为rand,示例
    void CTestDlg::OnButton1() 
    {
    // TODO: Add your control notification handler code here
    int a=0,b=0,c=0,d=0,e=0;
    a=rand()%9;
    b=rand()%9;
    c=rand()%9;
    d=rand()%9;
    e=rand()%9; CString str;
    str.Format("%d,%d,%d,%d,%d",a,b,c,d,e);
    AfxMessageBox(str);
    }
      

  3.   

    hohoh,钥匙,0,1之间,那就只能为0了。任何数%1都为0啊,呵呵
      

  4.   

    #include <stdlib.h>
    #include <stdio.h>
    #include <time.h>void main( void )
    {   /* Seed the random-number generator with current time so that
        * the numbers will be different every time we run.
        */
       srand( (unsigned)time( NULL ) );   /* Display  numbers. */
          printf( "  %d\n", rand() );
    }