How to make Random Numbers | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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; ?

19th Jun 2022, 4:29 AM
Cayden
2 Answers
0
hint: import random as r n = int(input()) print(r.randint(1, n))
19th Jun 2022, 4:35 AM
A͢J
A͢J - avatar
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; }
20th Jun 2022, 10:59 AM
Ujjawal Gupta
Ujjawal Gupta - avatar