Math.random() is used for three purposes including:
- Sampling: Depending on the implementation, some information could be gathered for only a small percentage of the visitors. Math.random() is used to determine, if a visitor should send the hit information or not.
- Fallback Visitor ID: If the visitor id cannot be retrieved from cookies, a random visitor id is generated. It could happen, if the user has cookies disabled (it uses two calls to math.random())
- Cache Busting: A random number is added to the end of requests to prevent browser caching.