#!/usr/bin/env bash

# Check if an argument was provided
if [ $# -eq 0 ]; then
    echo "Usage: $0 <max_number>"
    echo "Generate a random number between 1 and <max_number>"
    exit 1
fi

# Function to generate a random number between 1 and N
random_between_1_and_n() {
  local N=$1
  echo $(((RANDOM % N) + 1))
}

# Get the maximum number from the first argument
N=$1

# Validate that the input is a positive integer
if ! [[ "$N" =~ ^[1-9][0-9]*$ ]]; then
    echo "Error: Please provide a positive integer greater than 0"
    exit 1
fi

random_number=$(random_between_1_and_n "$N")
echo "Random number between 1 and $N: $random_number"
