Random in Python
random.randomrandom.randintrandom.uniformrandom.randrangerandom.choicerandom.samplerandom.shufflerandom.seedTwo integers are given:
pythonnum1 = 10
num2 = 20
Generate a random integer from the range given by our numbers.
Two integers are given:
pythonnum1 = 5
num2 = 30
Generate a pseudo-random integer from the range given by our numbers.
Given two fractional numbers:
pythonnum1 = 1.345
num2 = 14.784
Generate a pseudo-random real number from the range given by our numbers.
Two integers are given:
pythonnum1 = -2
num2 = 10
Generate a random real number from the range given by our numbers.
Three numbers are given:
pythonnum1 = 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:
pythonlst = [1, 2, 3, 4, 5]
Get a random item from this list.
Given a list:
pythonlst = [1, 2, 3, 4, 5]
Get a new list consisting of three random elements of the original list.
Given a list:
pythonlst = [1, 2, 3, 4, 5]
Shuffle the items in this list in random order.
The list with duplicates is given:
pythonlst = [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:
pythonnum = 7
Initialize it.
Given a tuple:
pythontlp = (10, 6, 2, 4)
Get a random number from it and then initialize it.