Table of Contents

    Exploring the Python random Module: Functions and Examples for Generating Random Data

    A Python module can contain objects like docstrings, variables constants, classes, objects, statements, functions.

    Python Random module is an in-built module of Python which is used to generate random numbers. These are pseudo-random numbers means these are not truly random. This module can be used to perform random actions such as generating random numbers, print random a value for a list or string, etc.

    Example: Printing a random value from a list

    # import random
    import random
      
    # prints a random value from the list
    list1 = [1, 2, 3, 4, 5, 6]
    print(random.choice(list1))

    Output

    2

    What are python modules? Name some commonly used built-in modules in Python?

    Python modules are files containing Python code. This code can either be function classes or variables. A Python module is a .py file containing executable code. Some of the commonly used built-in modules are:

    • Os
    • sys
    • math
    • random
    • data time
    • json