王欣逸女粉丝照片:如何用VC产生0.00型的随机数!

来源:百度文库 编辑:中科新闻网 时间:2024/04/29 17:20:42
帮忙看看下面程序对不对啊!

void CTestRandDlg::OnTestrand()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);

CString str;
str.Format("%.2f");

p_StaticWnd = GetDlgItem(IDC_STATIC);
p_StaticWnd->SetWindowText(str);

UpdateData(FALSE);

}
/////////////////////////////////////////////////////////////

#include <stdlib.h>
#include <stdio.h>
#include <time.h>

float RandomFloat( float flMin, float flMax )
{

int iRandomInt = RandomInt( (int)flMin, (int)flMax );
float flResult = iRandomInt + (float)( RandomInt(0,99) * 0.01 ) * ( iRandomInt > -1 ? 1 : -1 );

if( flResult > flMax ) flResult = flMax;
else if( flResult < flMin ) flResult = flMin;

return flResult;
}

结果::error C2065: 'RandomInt' : undeclared identifier
这怎么解决啊!

0.00这样的数字可以这样生成:(float)(rand()%1000)/100,
C++里生成随机数用rand(),在stdlib.h里声明的,返回一个int类型的随机数。RandomInt.....没听说过。