def generate(self, n=1):
"""
Generate a sample of luminosity values within [min, max] from
the above luminosity distribution.
"""
results = []
# Get the maximum value of the flux number density function,
# which is a monotonically decreasing.
M = self.fluxDensity(self.fmin)
for i in range(n):
while True:
u = np.random.uniform() * M
y = 10 ** np.random.uniform(low=np.log10(self.fmin),
high=np.log10(self.fmax))
if u <= self.fluxDensity(y):
results.append(y)
break
return results
评论列表
文章目录