Random Integer Generator within Range

  • Share this:

Code introduction


This function takes two integer arguments and returns a random integer within the given range.


Technology Stack : random

Code Type : Generate random numbers

Code Difficulty : Intermediate


                
                    
import random

def generate_random_number(arg1, arg2):
    if not isinstance(arg1, int) or not isinstance(arg2, int):
        raise ValueError("arg1 and arg2 must be integers")
    return random.randint(arg1, arg2)                
              
Tags: