Search Header Logo
TERM I 1-2 3-4 Generate pseudo-random numbers and sequences.

TERM I 1-2 3-4 Generate pseudo-random numbers and sequences.

Assessment

Presentation

Other

12th Grade

Hard

Created by

Аңсар Әкім

Used 9+ times

FREE Resource

11 Slides • 12 Questions

1

Welcome!
Programming
12 grade

2

Programming, Grade 12

1st term

2nd term

3rd term

4th term

Unit 12.1А: Python libraries.

Generate pseudo-random numbers and sequences.

Creating images.
Image processing.

Sound processing.

Unit 12.2A: PyGame


PyGame module overview. Game window.

Graphic primitives.
Animation.
Controlling the elements of the game.

Unit 12.3А: PyGame (continuation)

Using the game counter.
Images as characters in the game.

Object collisions.

Game development.

 

Unit 12.4A: Chatbot development.


Introduction to chatbots

Chatbot (Vkontakte)

Chatbot (Telegram).

3

​What do we already know?

4

Unit 11.1А: Basic structures of the Python programming language
Unit 11.2А: Data structures.

Unit 11.3А: Data structures (continuation).

Unit 11.3B: Functions.

Unit 11.4A: Object Oriented Programming (ООP)

Programming 11 grade

5

12.6.1.1 uses the functions of the library Random to get a pseudo-random number;

12.6.1.2 Determine the function of the library Random for the specified task;

12.6.1.3 Identify code snippets that use random sequence generation;

12.6.1.4 Solve problems using random numbers and random sequences.

Generate pseudo-random numbers and sequences.

6

Generate pseudo-random numbers and sequences.

media

7

8

​Let's solve tasks!

1. Generate Random Numbers: Generate a sequence of random numbers between a given range.

2. Simulate Coin Toss: Simulate a coin toss using the random function.

3. Randomize List Elements: Shuffle the elements of a list randomly.

4. Random Password Generator: Generate a random password with a given length.

5. Random Sample from List: Select a random sample of elements from a list.


6. Guessing Game Task:

Create a guessing game where the computer generates a random number between a specified range, and the player has to guess the number. The game should provide hints to the player, indicating whether their guess is too high or too low. The player should continue guessing until they correctly guess the number.

9

Multiple Choice

LO: 12.6.1.1 Which library is used to generate pseudo-random numbers in Python?

1

math

2

random

3

rand

4

pseudo

10

Multiple Choice

LO: 12.6.1.2 If you want to generate a random integer between 5 and 10 (inclusive), which function would you use from the random library?

1

randint(5, 10)

2

randrange(5, 11)

3

choice([5, 6, 7, 8, 9, 10])

4

uniform(5, 10)

11

Multiple Choice

LO: 12.6.1.1 What function from the random library is used to generate a random floating-point number between 0 and 1?




1

randrange()

2

uniform()

3

random()

4

choice()

12

Multiple Choice

LO: 12.6.1.2 To shuffle the elements of a list my_list randomly, which function would you use from the random library?

1

shuffle(my_list)

2

randomize(my_list)

3

random.shuffle(my_list)

4

mix(my_list)

13

Multiple Choice

LO: 12.6.1.3 Which code snippet demonstrates the correct way to generate a random sequence of 5 lowercase letters?

1

sequence = random.choice('abcdefghijklmnopqrstuvwxyz', 5)

2

sequence = random.sample('abcdefghijklmnopqrstuvwxyz', 5)

3

sequence = random.shuffle('abcdefghijklmnopqrstuvwxyz')[:5]

4

sequence = random.random('abcdefghijklmnopqrstuvwxyz', 5)

14

​Let's solve tasks!

Learning Objective: 12.6.1.1:

Task 1: Dice Roll Simulation Create a program that simulates rolling a fair 6-sided die 50 times using the random library. Count and display the frequency of each roll outcome (1 to 6).
Learning Objective: 12.6.1.2

Task 2: Random Password Generator Write a program that generates a random password of a given length using the random library's functions. Allow users to choose whether to include uppercase letters, lowercase letters, digits, and special characters.
Task 3: Randomized Selection Design an algorithm to select a random element from a given list using the random library. Implement it and test it with various input lists.

15

Multiple Choice

LO: 12.6.1.3 Which of the following code snippets demonstrates the correct way to select two items from the list my_list randomly?

1

random.random(my_list, 2)

2

random.choice(my_list, 2)

3

random.sample(my_list, 2)

4

random.shuffle(my_list)[:2]

16

Multiple Choice

LO: 12.6.1.1 Which of the following statements is true about pseudo-random numbers?

1

Pseudo-random numbers are truly random and unpredictable.

2

Pseudo-random numbers are generated using physical randomness sources.

3

Pseudo-random numbers are generated using deterministic algorithms.

4

Pseudo-random numbers are generated using a hardware random number generator.

17

Multiple Choice

LO: 12.6.1.2 You want to generate a random boolean value (True or False). Which function would you use from the random library?

1

random.choice([True, False])

2

random.boolean()

3

random.random_bool()

4

random.randint(0, 1)

18

Learning Objective: 12.6.1.3:

Task 4: Random Word Generator Develop a program that generates a random word by selecting characters randomly from a given set. Print the generated word.
Task 5: Shuffled Sentence Write a program that takes a sentence as input and randomly shuffles the order of words using the random library. Display the shuffled sentence.

Task 6: Randomized Quiz Questions Create a quiz application that displays multiple-choice questions with randomized answer options. Use the random library to shuffle the answer choices.

Learning Objective: 12.6.1.4:

Task 7: Casino Game Simulation Develop a simulation of a imple casino game (e.g., rolling dice for points) using the random library. Keep track of player scores over multiple rounds.

19

Multiple Choice

LO: 12.6.1.3 Which code snippet demonstrates the correct way to randomly shuffle the characters in a string my_string?

1

random.shuffle(my_string)

2

shuffled_string = ''.join(random.sample(my_string, len(my_string)))

3

shuffled_string = my_string.random_shuffle()

4

shuffled_string = random.shuffle_str(my_string)

20

Multiple Choice

LO: 12.6.1.2 What is the purpose of the random.seed() function in the random library?

1

To generate truly random numbers.

2

To set the range for random numbers.

3

To initialize the pseudo-random number generator's internal state.

4

To generate cryptographically secure random numbers.

21

Multiple Choice

LO: 12.6.1.3 You want to generate a list of five random integers between 1 and 100. Which code snippet accomplishes this?

1

random.integers(1, 100, 5)

2


random.randint(1, 100, 5)

3

[random.randint(1, 100) for _ in range(5)]

4

random.sequence(1, 100, 5)

22

​Let's solve advanced tasks!

1 . Random Walk Simulation: Simulate a 2D random walk starting from a central point. Generate a series of random steps (up, down, left, right) and visualize the path.
2. Randomized Permutation Generation: Generate a random permutation of numbers from 1 to N.
3. Randomized String Generation: Generate a random string of a certain length using a given set of characters.
4. Randomized Game Strategies: Develop a simple two-player game (like Rock-Paper-Scissors) where each player uses a randomized strategy.
5. Randomized Binary Search: Implement a randomized version of the Binary Search algorithm to find an element in a sorted array.

23

Poll

Thank you for completing this learning module on generating pseudo-random numbers and sequences using the random library. Your feedback is important to us. On a scale of 1 to 5, how would you rate your understanding of the topic after completing this module?

  • 1: Very Limited Understanding

  • 2: Limited Understanding

  • 3: Moderate Understanding

  • 4: Good Understanding

  • 5: Very Good Understanding

Welcome!
Programming
12 grade

Show answer

Auto Play

Slide 1 / 23

SLIDE