This Photo by Unknown author is licensed under CC BY-SA.
WHAT IS RANDOM?
• The random provides access to functions
that support many operations.
• To generate random numbers.
HOW TO USE THE RANDOM? • We want the computer to pick a random number in a given range.
• Pick a random element from a list, pick a random card
from a deck, flip a coin • etc. RANDOM FUNCTION The Random contains some very useful functions.
• RANDINT
• RANDOM
• CHOICE
• SHUFFLE
• RANDRANGE RANDINT • If we wanted a random integer, we can use the randint function.
• Randint accepts two parameters: a lowest and a highest number.
• Generate integers between 1,5. The first value should be less
than the second. • Syntax :
randint(start, end)
Parameters :
(start, end) : Both of them must be integer
type values. RANDOM
• This number is used to generate a float
random number less than 1 and greater or equal to 0. • If you want a larger number, you can multiply it.
• For example, a random
number between 0 and 100. This function is used CHOICE to generate 1 random number from a container.
This Photo by Unknown author is licensed under CC BY-SA.
• Generate a random value from the sequence. • • • random.choice( ['red', 'black', 'green'] ). • • • The choice function can often be used for choosing a random element from a list.
This Photo by Unknown author is licensed under CC BY-SA.
SHUFFLE
This function is used to shuffle the entire list to
randomly arrange them.
This Photo by Unknown author is licensed under CC BY-SA.
• The shuffle function, shuffles the elements in list in place, so they are in a • random order. • • • random.shuffle(list) •
This Photo by Unknown author is licensed under CC BY-SA.
RANDRANGE This function is also used to generate random number but within a range specified in its arguments. This function takes 3 arguments, beginning number (included in generation), last number (excluded in generation) and step ( to skip numbers in range while selecting).
This Photo by Unknown author is licensed under CC BY-SA.
• Generate a randomly selected element from range(start, stop, step) • • • random.randrange(start, stop[, step])
This Photo by Unknown author is licensed under CC BY-SA.
THANK YOU! Okey keyo!
This Photo by Unknown author is licensed under CC BY-SA.