c++中怎么产生0-1之间的随机数

http://zhidao.baidu.com/question/688719686574659564.html

#include 
#include 

using namespace std;

double GetRand();

int main()
{
	cout << GetRand() << endl;
	return 0;
}

double GetRand()
{
	srand(time(NULL));

	int iRand = rand();

	iRand %= 10000; // 取0 ~ 9999

	return iRand / 10000.0; // 注意加".0"

	// PS:保留几位小数就合适求舍,求商
}


你可能感兴趣的:(c++中怎么产生0-1之间的随机数)