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

Random-Function-Unveiling-the-Power-of-Randomness-in-Programming.ppt

This presentation discusses the random function in programming, highlighting its unpredictable outputs and common applications in simulations, games, and testing. It provides an overview of random functions in Python, including examples like random.random() and random.randint(). Additionally, it covers various applications such as cryptography and testing, emphasizing the importance of randomness in programming.

Uploaded by

Prince Thakan
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Random-Function-Unveiling-the-Power-of-Randomness-in-Programming.ppt

This presentation discusses the random function in programming, highlighting its unpredictable outputs and common applications in simulations, games, and testing. It provides an overview of random functions in Python, including examples like random.random() and random.randint(). Additionally, it covers various applications such as cryptography and testing, emphasizing the importance of randomness in programming.

Uploaded by

Prince Thakan
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 13

Random Function:

Unveiling the Power of


Randomness in
Programming
This presentation will explore the random function in
programming, its uses, and key functionalities.
Introduction to the Random Function
1 Unpredictable Outputs 2 Common Uses
The random function generates Commonly used in simulations, games, and
unpredictable outputs. testing.
Key Features of the Random Function
Random Numbers and Values Variety of Functions

Produces random numbers or values. Offers different functions for specific use cases.
The Random Module in
Python
To use random functions in Python, import the random
module:
Overview of Random Functions
Function Description Example

random.random() Generates a random float random.random() → 0.572


between 0 and 1 (exclusive)

random.randint(a, b) Returns a random integer random.randint(1, 10) → 7


between a and b (inclusive)

random.uniform(a, b) Returns a random float random.uniform(5.5, 9.5) → 6.3


between a and b

random.choice(seq) Selects a random element random.choice(['red', 'blue',


from a sequence 'green']) → 'blue'

random.shuffle(lst) Randomly rearranges random.shuffle([1, 2, 3]) → [3, 1, 2]


elements in a list
Applications of Random
Functions
Games Simulations
Shuffling cards, Weather predictions,
randomizing moves. modeling real-world
scenarios.

Cryptography Testing
Random key generation Generating random test
for secure data for software
communication. validation.
Example Program
(A) (B)
Any integer between 0 and 5. Any integer between 1 and 4.

(C) (D)
Any integer between 1 and 5. Any integer between 0 and 4.

Correct Answer: (C)


Q 2:What will the following code output?

(A) apple (B) banana

(C) cherry (D) Any one of the above

Correct Answer: (D)


Q 3: Which function generates a random
float between two numbers, a and b?
(A) (B)
randint(a, b)

(C) (D)
uniform(a, b) shuffle()

Correct Answer: (C)


(A) (B)
Sort the list in ascending order. Sort the list in descending order.

(C) (D)
Rearrange the list in random order. Remove duplicates from the list

Correct Answer: (C)


(A) (B)
A random float between 0 and 1. A random integer between 0 and 1.

(C) (D)
A random float between 1 and 10. A random integer between 1 and 10.

Correct Answer: (A)


Thank You

You might also like