+ 1
How to make Random Numbers
what code would i input to give a variable a random output. say i'm working on a baseball game, and i need random numbers to give the players stats, what code do i write to do that? would it be something like : int a = 1, 2, or 3; ?
2 Answers
0
hint:
import random as r
n = int(input())
print(r.randint(1, n))
0
// Below is the code to generate a random number
#include <iostream>
using namespace std;
int main()
{
srand(time(0));
int min,max;
cout<<"Define a range : ";
cin>>min>>max;
int a=min+rand()%max;
cout<<"Random number : "<<a<<endl;
x++;
return 0;
}