Typer CLI for Random Number Generation

  • Share this:

Code introduction


This function uses the Typer library to create a simple command-line application that allows users to generate a random number within a specified range.


Technology Stack : Typer

Code Type : Python Function

Code Difficulty : Intermediate


                
                    
import typer
import random

def generate_random_number(min_val, max_val):
    """
    Generate a random number between min_val and max_val.
    """
    return random.randint(min_val, max_val)

def xxx():
    app = typer.Typer()
    
    @app.command()
    def random_number(min_val: int, max_val: int):
        """Generate a random number between min_val and max_val."""
        print(generate_random_number(min_val, max_val))
    
    app.run()                
              
Tags: