How do I find the Rand_Max on my system using C++ code? Just a theory question.

Recommended Answers

All 3 Replies

#include <iostream>

using namespace std;

int main()
{	
	double randomMax = 0.0;
	int rand_max = rand();

	//calculate rand_max
	randomMax = 0 + rand_max;

	//display the value of the RAND_MAX constant
	cout << randomMax << endl;


    return 0;
}   //end of main function

The problem is I'm only getting 41 as the number, which I know isn't correct.

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
   cout << "RAND_MAX = " << RAND_MAX << "\n";
   return 0;
}
commented: Smart Guy, knows how to use google. +1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.