Using Random in Python code example
Example 1: how to use random in python
import random
print(random.randint(3, 7))
array = [cars, bananas, jet]
print(random.choice(array))
Example 2: python random
import random
print(random.randint(1, 100))
Example 3: import random python
import random
Example 4: random in python
import time
import random
gamelist = ['You lose the race', 'You win the race']
Player = input('')
print(' Hi ' + Player + ' , welcome to the running race game')
time.sleep(2)
print('3')
time.sleep(1)
print('2')
time.sleep(1)
print('1')
time.sleep(2)
print(random.choice(gamelist))
Example 5: random module in python
>>> random()
0.37444887175646646
>>> uniform(2.5, 10.0)
3.1800146073117523
>>> expovariate(1 / 5)
5.148957571865031
>>> randrange(10)
7
>>> randrange(0, 101, 2)
26
>>> choice(['win', 'lose', 'draw'])
'draw'
>>> deck = 'ace two three four'.split()
>>> shuffle(deck)
>>> deck
['four', 'two', 'ace', 'three']
>>> sample([10, 20, 30, 40, 50], k=4)
[40, 10, 50, 30]
Example 6: import random in python
def DisplayOddNum(N):
pass
for x in DisplayOddNum(20)
print(x)