statistics.NormalDist.samples

Full name
statistics.NormalDist.samples
Library
statistics
Syntax

statistics.NormalDist.samples(n, *, seed = None)

Description

The samples method of an object of type statistics.NormalDist generates a sample of n values extracted from the distribution.

Parameters
  • n: Number of samples to generate.
  • seed: Seed of the random number generator. By default it takes the value None.
Result

The samples method returns a list of values of type float.

Examples

If we start from the following normal distribution:

dist = statistics.NormalDist(mu = 5, sigma = 2)

...we can get a sample of 5 numbers with the following code:

dist.samples(n = 5, seed = 18)
[6.232076430737973,
7.673236977097618,
4.32696959286573,
6.145251505319521,
2.6704768202851605]

As we have used a seed for the random number generator, the generated sample will be the same every time we run the method.

Submitted by admin on Fri, 04/16/2021 - 10:08