from scipy import stats
import numpy as np
def bounded_normal(min_val, max_val, size=None):
# Set mean to the center of the range
mean = (min_val + max_val) / 2
# Set standard deviation to cover most of the range
# A common heuristic is to make 3 standard deviations cover the range
std = (max_val - min_val) / 6
# Calculate the corresponding normalized bounds
a = (min_val - mean) / std
b = (max_val - mean) / std
# Use scipy's truncated normal distribution
return stats.truncnorm.rvs(a, b, loc=mean, scale=std, size=size)
from scipy import stats
import numpy as np
def bounded_normal(min_val, max_val, size=None):
# Set mean to the center of the range
mean = (min_val + max_val) / 2