from scipy.special import softmax
from scipy.stats import beta
import numpy as np
import random

_rng = np.random.default_rng()

def resolve_rng(np_rng):
	global _rng
	return _rng if np_rng is None else np_rng

def exp_uniform_blend(n: int, alpha: float, np_rng=None ) -> list[float]:
	global _rng
	rng = resolve_rng(np_rng)
	exp_probs = np.exp(-np.arange(n))
	exp_probs /= exp_probs.sum()
	uniform = np.ones(n) / n
	probs = ( (1 - alpha) * exp_probs + alpha * uniform)
	return rng.permutation( probs ).tolist()

def beta_dist( n, a, b, np_rng=None ):
	global _rng
	rng = resolve_rng(np_rng)
	points = np.linspace(0, 1, n + 2 )[ 1:-1] 
	values = beta.pdf(points, a, b)
	probs  = values / values.sum()
	return rng.permutation( probs ).to_list()

def dirichlet_dist(n, alpha, np_rng=None ):
	global _rng
	rng = resolve_rng(np_rng)
	return rng.dirichlet(np.ones(n) * alpha)

def uniform_dist( n ):
	return np.ones(n) / n

def srand_global(seed: int):
	global _rng
	# _rng = np.random.default_rng(11)
	np.random.seed(seed)
	random.seed(seed)