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

Programming 1 Term 2 Lesson

Uploaded by

abenovsanzhar
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Programming 1 Term 2 Lesson

Uploaded by

abenovsanzhar
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

GENERATE RANDOM

SEQUENCES.
12.6.1.1 USE 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;
Let’s remember!

HTTPS://WWW.YOUTUBE.COM/WATCH?V=KZQSDVZOFNA
WHAT THE FUNCTION DOES?
Function What it does
randint(x, y) Generates a random integer from x to y, including the x and y.
randrange(start, stop,
Generates a random integer in the range(start, stop, step)
step)
random() Generates a random floating-point number in the interval [0,1)

uniform(x, y) It generates a floating-point value between x and y.


Selects k unique random elements from a population sequence
sample(population, k)
or set.
choice(seq) Chooses a random element from a non-empty sequence seq.

shuffle(x) Shuffles list x in place.


Generates the same sequence of random numbers every time
seed(x)
you call seed(x).
GENERATE RANDOM
STRINGS AND PASSWORDS
IMPORT STRING AND RANDOM MODULE

• The string module contains various string constant which contains the
ASCII characters of all cases. It has separate constants for lowercase,
uppercase letters, digits, and special symbols, which we use as a
source to generate a random string.
Pass string constants as a source of randomness to the random module
to create a random string
TASK 1 ”STRING"

Write a program
• to pick a random character from a given String.
• 3 unique random character from a given String.
• 3 random characters with replacement from a given String.
Example.
Input: University
Random output: s, n e r, UiU
TASK 2 ENCRYPTION PROGRAM

• create the simplest encryption program for


given string.
• Set an random number in the range 1..24.
• Perform a cyclic shift of all the letters of the
string by this number.
TASK 3 “PASSWORD”

Create a password by Generating random String of length 5.

Note: String must be the combination of the UPPER case and lower case letters only. No
numbers and a special symbol.

Example
Output: Random String is sWdRF
TASK 4 “PASSWORD” (ADVANCED LEVEL)

Generate a random Password which meets


the following conditions:
• Password length must be 10 characters long.
• It must contain at least 2 upper case letters, 1
digit, and 1 special symbol.

You might also like