Skip to content

Commit c17971c

Browse files
committed
feat: add gauss func + add import math methods
1 parent 64ff614 commit c17971c

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

pycustomrand/random_generator.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from .custom_round import true_round
2+
from math import sqrt, log, cos, pi
23
from time import sleep, time_ns
34
from typing import Any
45

@@ -148,6 +149,21 @@ def triangular(low: float = 0.0, high: float = 1.0, mode: float = None) -> float
148149
low, high = high, low
149150
return low + (high - low) * (uniform * cutoff) ** 0.5
150151

152+
@staticmethod
153+
def gauss(mu: float = 0.0, sigma: float = 1.0) -> float:
154+
"""
155+
Возвращает случайное число с нормальным (гауссовым) распределением.
156+
Алгоритм Бокса-Мюллера.
157+
158+
mu - среднее значение, центр колокола (математическое ожидание).
159+
sigma - стандартное отклонение, ширина колокола.
160+
"""
161+
u1 = PseudoRandom.random()
162+
u2 = PseudoRandom.random()
163+
z0 = sqrt(-2.0 * log(u1)) * cos(2.0 * pi * u2)
164+
return z0 * sigma + mu
165+
166+
151167
# -------------------- Байтовые функции --------------------
152168

153169
@staticmethod

0 commit comments

Comments
 (0)