44"""
55This module provides random number generators.
66"""
7+ from typing import Any
8+ from typing import Any
9+ from typing import Literal
710
811import numpy as np
12+ from numpy import ndarray
913from numpy .random import BitGenerator
1014from numpy .random import Generator
1115
@@ -82,7 +86,7 @@ def randoms(self, randoms: np.ndarray) -> np.ndarray:
8286
8387
8488class DefaultNormal (Normal ):
85- """The default normal random variate ."""
89+ """The default normal random deviate ."""
8690
8791 _g : Generator
8892
@@ -100,3 +104,65 @@ def random(self) -> float:
100104 def randoms (self , randoms : np .ndarray ) -> np .ndarray :
101105 self ._g .standard_normal (dtype = randoms .dtype , out = randoms )
102106 return randoms
107+
108+
109+ class DecileNormal (Normal ):
110+ """
111+ The decile normal random deviate.
112+
113+ Generates random deviates, which are uniformly distributed in a
114+ selected decile of the standard normal distribution.
115+ """
116+
117+ _g : Generator
118+
119+ _q : ndarray [float , float ]
120+ """The deciles of the normal distribution."""
121+ _s : int | Literal [0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ]
122+ """The decile selector."""
123+
124+ def __init__ (
125+ self , s : int , seed : int | np .ndarray | BitGenerator | None = None
126+ ):
127+ """
128+ Creates a new random deviate.
129+
130+ :param s: The decile selector.
131+ :param seed: The seed.
132+ """
133+ self ._s = s % 10
134+ self ._g = default_generator (seed )
135+ self ._q = np .ndarray (
136+ [
137+ - 3.09023 ,
138+ - 1.28155 ,
139+ - 0.841621 ,
140+ - 0.524401 ,
141+ - 0.253347 ,
142+ 0.0 ,
143+ 0.253347 ,
144+ 0.524401 ,
145+ 0.841621 ,
146+ 1.28155 ,
147+ 3.09023 ,
148+ ]
149+ )
150+
151+ def random (self ) -> float :
152+ return (self .sup - self .inf ) * self ._g .random () + self .inf
153+
154+ def randoms (self , randoms : np .ndarray ) -> np .ndarray :
155+ self ._g .random (dtype = randoms .dtype , out = randoms )
156+ randoms *= self .sup - self .inf
157+ randoms += self .inf
158+ return randoms
159+
160+ @property
161+ def sup (self ) -> float :
162+ """Returns the supremum of the selected decile."""
163+ return self ._q [self ._s + 1 ]
164+
165+ @property
166+ def inf (self ) -> float :
167+ """Returns the infimum of the selected decile."""
168+ return self ._q [self ._s ]
0 commit comments