You can download this code by clicking the button below.
This code is now available for download.
This code defines a function called random_number_generator that generates a random number within a specified range. It uses the Click library to create a command-line interface that allows the user to input the minimum and maximum values, and then displays the generated random number.
Technology Stack : Click, random
Code Type : Command line tool
Code Difficulty : Intermediate
import click
import random
def random_number_generator(min_value, max_value):
"""Generate a random number between min_value and max_value."""
click.echo(f"Generating a random number between {min_value} and {max_value}...")
return random.randint(min_value, max_value)
click.command()
@click.argument('min_value', type=int)
@click.argument('max_value', type=int)
def cli(min_value, max_value):
"""Command line interface to generate a random number."""
result = random_number_generator(min_value, max_value)
click.echo(f"Random number: {result}")