Answers for "randomize function in c++"

C++
4

random in c++

#include <iostream>
#include <stdlib.h>     
#include <time.h> 
using namespace std;

int main()
{
	int num;
	srand(time(0));
		num = rand() % 10 + 1;
		cout << num << endl;
}
Posted by: Guest on May-09-2021
2

cpp random number in range

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

random function c++

#include<iostream>
#include<cstdlib>
using namespace std;
 
int main(){
 
    // Providing a seed value
    srand((unsigned) time(NULL));
 
    // Loop to get 5 random numbers
    for(int i=1; i<=5; i++){
         
        // Retrieve a random number between 100 and 200
        // Offset = 100
        // Range = 101
        int random = 100 + (rand() % 101);
 
        // Print the random number
        cout<<random<<endl;
    }
 
    return 1;
}
Posted by: Guest on June-14-2021

Browse Popular Code Answers by Language