0% found this document useful (0 votes)
21 views

Randomized: Reported By: Joshua B. Abergas John Azarelq. Tunguia

The document discusses random number generation in Python. It introduces the random module and some of its key functions: randint generates random integers within a given range, random generates random floats between 0 and 1, choice selects a random element from a list, shuffle randomly reorders the elements of a list in place, and randrange generates random integers within a given range with an optional step value. These functions allow programmers to incorporate randomness into their programs.

Uploaded by

kimberly
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Randomized: Reported By: Joshua B. Abergas John Azarelq. Tunguia

The document discusses random number generation in Python. It introduces the random module and some of its key functions: randint generates random integers within a given range, random generates random floats between 0 and 1, choice selects a random element from a list, shuffle randomly reorders the elements of a list in place, and randrange generates random integers within a given range with an optional step value. These functions allow programmers to incorporate randomness into their programs.

Uploaded by

kimberly
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

RANDOMIZED

R E P O R T E D B Y:

JOSHUA B. ABERGAS

JOHN AZAREL Q. TUNGUIA

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.

You might also like