Grim
Grim

Reputation: 1

How would I generate 100000 random numbers using a normal distribution with a specified mean and standard deviation?

import pandas as pd
import numpy as np

from numpy.random import randn

s = pd.Series(np.random.randn(100000))

Upvotes: 0

Views: 771

Answers (2)

Paul Cornelius
Paul Cornelius

Reputation: 10936

No third party packages needed, just the standard Python library:

import random
mu = 0.0
sigma = 10.0
for _ in range(100000):
    print(random.gauss(mu, sigma))

You could also use random.normalvariate instead of random.gauss.

Upvotes: 1

jrbergen
jrbergen

Reputation: 658

You could do this using e.g. numpy's random subpackage.

import numpy as np

mean: float = 100.0
stdev: float = 3.0
n_samples: int = 100_000

samples: np.ndarray = np.random.normal(loc=mean,
                                       scale=stdev,
                                       size=n_samples)

Upvotes: 1

Related Questions