Simulating Random User Location

  • Share this:

Code introduction


This function simulates a user's random location feature. It generates a random latitude and longitude coordinates and prints them out.


Technology Stack : Locust, random

Code Type : Function

Code Difficulty : Intermediate


                
                    
def random_user_location(user):
    from locust import Locust, task
    from random import randint
    
    @task
    def get_random_location():
        lat = 40 + randint(-5, 5)
        lon = -75 + randint(-10, 10)
        print(f"User {user} is located at ({lat}, {lon})")
    
    get_random_location()                
              
Tags: