Random Number Generation Endpoint

  • Share this:

Code introduction


This function takes two parameters, min_value and max_value, and returns a JSON response containing a random integer within the specified range.


Technology Stack : Starlette, random

Code Type : API Function

Code Difficulty : Intermediate


                
                    
from starlette.responses import JSONResponse
from starlette.requests import Request
import random

def random_number_generator(min_value, max_value):
    # Generate a random number between min_value and max_value
    return JSONResponse({"random_number": random.randint(min_value, max_value)})

# JSON Explanation