Random in Python
random.random
random.randint
random.uniform
random.randrange
random.choice
random.sample
random.shuffle
random.seed
Two integers are given:
num1 = 10
num2 = 20
Generate a random integer from the range given by our numbers.
Two integers are given:
num1 = 5
num2 = 30
Generate a pseudo-random integer from the range given by our numbers.
Given two fractional numbers:
num1 = 1.345
num2 = 14.784
Generate a pseudo-random real number from the range given by our numbers.
Two integers are given:
num1 = -2
num2 = 10
Generate a random real number from the range given by our numbers.
Three numbers are given:
num1 = 5
num2 = 50
num3 = 4
Generate a random number from the range specified by the first and second numbers. Let the third number determine the sampling step.
Given a list:
lst = [1, 2, 3, 4, 5]
Get a random item from this list.
Given a list:
lst = [1, 2, 3, 4, 5]
Get a new list consisting of three random elements of the original list.
Given a list:
lst = [1, 2, 3, 4, 5]
Shuffle the items in this list in random order.
The list with duplicates is given:
lst = [1, 1, 1, 2, 2, 3, 3, 4, 5]
Get three random elements from the list so that no elements are repeated in the sample.
Given a number:
num = 7
Initialize it.
Given a tuple:
tlp = (10, 6, 2, 4)
Get a random number from it and then initialize it.