+ 2
How do I make a code set radom number values to a int variable C++
Random numbers
12 Respostas
+ 3
cout << "random number = " << rand() << endl;
int x = rand();
rand() % 10 + 1; // Numbers from 1 to 10
+ 3
It really helped you or there are still some questions?
+ 2
wait It is continously always the same random number why wont it change?
+ 1
Your the best
+ 1
yeah I forgot the rand() part
+ 1
At last it works. Glad)
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main() {
int m;
srand(time(NULL));
for(int i = 0; i < 10; i++) {
m = 10 + rand() % 100; cout << m << endl; } return 0;
}
+ 1
thank the code is running perfetly , aldo I dont fuly understand how the time element work
+ 1
I wil research it.
0
Thank you
0
oh so time is also an effect that is used to change the number.
0
I will research it