Random Integer List Generator

  • Share this:

Code introduction


This function generates a list of random integers within a specified range.


Technology Stack : random

Code Type : Function

Code Difficulty : Intermediate


                
                    
import random

def generate_random_list(size, min_value, max_value):
    """
    Generate a list of random integers within a specified range.

    :param size: int, the number of elements in the list
    :param min_value: int, the minimum value in the range
    :param max_value: int, the maximum value in the range
    :return: list, a list of random integers
    """
    return [random.randint(min_value, max_value) for _ in range(size)]                
              
Tags: