Untitled Document
Random Module - Generating Random Numbers
1. Introduction Click Here
       #********* Source Code From Website - Mangadaku - visit us at -http://mangadaku.com/ *****  
       # Introduction 
       # Random Module is used to generate some random values 
       # By default Random Module generates floating point numbers between 0 and 1 
       # where 0 and 1 are  non inclusive    
         
       
2. Program - To Print Random Numbers Click Here
       #********* Source Code From Website - Mangadaku - visit us at -http://mangadaku.com/ *****      
       # Program - To Print Random Numbers
       
       import random
       value = random.random()
       print(value)
       
       
3. Getting random values from a specific range Click Here
       #********* Source Code From Website - Mangadaku - visit us at -http://mangadaku.com/ *****      
       # Getting random values from a specific range
       # we have 2 methods - 
       # 1) randint which will generate integer value between given range
       # 2) randuniform - this will generate floating point numbers betwwen given range 
       # IMP - here the values given in range are inclusive 

       import random
       value = random.randint(1, 6)
       print(value)
       value = random.uniform(1, 6)
       print(value)

       
4. choice method () ; this method will select any random value from list Click Here
       #********* Source Code From Website - Mangadaku - visit us at -http://mangadaku.com/ *****      
       # choice method () ; this method will select any random value from list
       # Below example will print 50 characters from file 
       
       greetings = ['Hello', 'Hi', 'Hey', 'Howdy', 'Hola']
       value = random.choice(greetings)
       print(value + ', Mangesh !')

       
5. Shuffle Method Click Here
       #********* Source Code From Website - Mangadaku - visit us at -http://mangadaku.com/ *****      
       # Shuffle Method 
       # Shuffle method shuffles the existing positional arguments i.e list 
       # The below example is just to demonstarte to select 5 random cards from deck of 52 cards
       
       import random 
       deck = list(range(1, 53))            
       hand = random.sample(deck, k=5)                    
       print(hand)
       
       
Untitled Document