Gistlib Logo

gistlib

generate a random number between 0 and 1 in python

To generate a random number between 0 and 1 in Python, you can use the random module's random() function:

main.py
import random

random_number = random.random()

print(random_number)
69 chars
6 lines

The random() function returns a random float number between 0 and 1 (inclusive of 0 but exclusive of 1).

similar python code snippets

generate a random number between 0 and 1 in python
find the sum of all elements in an array in python
how to get distinct combinations of a set in python
how to get distinct permutations of a set in python
how to get all combinations of a set in python
how to get the power set of a set in python
define a function that takes a list of numbers as an argument and returns the sum of the numbers in the list. in python
find the median of all elements in an array in python
find the average of all elements in an array in python
find the largest number in the following list of numbers: [1, 3, 4, 2, 5] in python

related categories

python
random
number generation

gistlibby LogSnag