Answers for "c++ generate random numbers in range"

C++
1

cpp random number in range

int range = max - min + 1;
int num = rand() % range + min;
Posted by: Guest on February-02-2021
0

c++ generate random numbers in range

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int main()
{
	srand(time(0));

	for (int i = 0; i <= 10; i++)
	{
		int start = 3;
		int end = 8;
		cout << start + rand() % (end - start + 1);
	}
}
Posted by: Guest on April-25-2021

Code answers related to "c++ generate random numbers in range"

Browse Popular Code Answers by Language