Random Integer Generator Function

  • Share this:

Code introduction


The function takes two integer arguments, arg1 and arg2, and returns a random integer between these two numbers (inclusive). If the arguments provided are not integers, the function raises a ValueError.


Technology Stack : random.randint, isinstance, ValueError

Code Type : Function

Code Difficulty : Intermediate


                
                    
import random
import math
import os
import re
import json
import time
import subprocess
import sys
import threading

def xxx(arg1, arg2):
    # This function generates a random number between arg1 and arg2 (inclusive)
    if not (isinstance(arg1, int) and isinstance(arg2, int)):
        raise ValueError("Both arguments must be integers.")
    if arg1 > arg2:
        arg1, arg2 = arg2, arg1
    return random.randint(arg1, arg2)