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;
}
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;
}
cpp random number in range
int range = max - min + 1;
int num = rand() % range + min;
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;
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us