Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
communitycreator
random
lognormvariate

What is the random.lognormvariate() method in python?

abhilash

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The lognormvariate() method is used to get floating values chosen from a Lognormal distribution with the given mean and standard deviation.

What is lognormal distribution?

The Gaussian distribution, also known as the Normal distribution, is a symmetric probability distribution centered on the mean, indicating that data near the mean occur more frequently than data far from it. The distribution of the logarithmic values of the normal distribution is known as a lognormal distribution.

Syntax


random.lognormvariate(mu, sigma)

Parameters

  • mu: The mean value.
  • sigma: The standard deviation value. This value must be greater than zero.

Return value

This method returns a floating point value.

Code

import random
#mean value
mu = 5
#standard deviation
sigma = 2.1
val = random.lognormvariate(mu, sigma=sigma)
print("random.lognormvariate(%s, %s) = %s" % (mu, sigma, val))

Explanation

  • Line 1: We import random module.
  • Line 4: We define the mean value, mu.
  • Line 7: We define the standard deviation value, sigma.
  • Line 8: We store the value returned by the lognormvariate() method passing mu and sigma as parameters in the variable val.
  • Line 10: We print val on to console.

RELATED TAGS

python
communitycreator
random
lognormvariate

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring