How can I get a random value in python? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How can I get a random value in python?

23rd Oct 2018, 5:57 AM
Alexis Durand
Alexis Durand - avatar
3 Answers
+ 4
Highly depends on what you want to do. Look at python's random module. It has functions for random integers, random doubles, random selections from lists, random Gaussian distributed numbers...
23rd Oct 2018, 6:11 AM
Anna
Anna - avatar
+ 2
First you must import random module in python. then you may use : random.random()# random number between 0 and 1 random.uniform(x,y) # here x and y are two numbers and this generates a random float number between x and y or random.randint(x,y)# it generates random integer between x and y.
23rd Oct 2018, 6:12 AM
Pushkar Raj
Pushkar Raj - avatar
0
use the random function for example: import random for x in range(10): print random.randint(1,200)
23rd Oct 2018, 3:46 PM
Mwaniki Jacob
Mwaniki Jacob - avatar