86#ifndef LIB_RANDOM_DRAW_H
87#define LIB_RANDOM_DRAW_H
120 template<
typename T, T max, T min =T(0), T zero =min>
123 static_assert (min < max);
124 static_assert (min <= zero and zero < max);
126 static constexpr T
maxVal() {
return max; }
127 static constexpr T
minVal() {
return min; }
141 operator T
const&()
const
149 namespace random_draw {
157 : function<Limited<uint, max>(void)>
182 using Fun = function<Sig>;
196 return Tar::zeroVal();
205 return Tar::zeroVal();
210 auto org = Tar::zeroVal();
216 return Tar{floor (val)};
225 return Tar{floor (val)};
235 return Tar{floor (val)};
278 template<
class FUN,
typename =disable_if_self<RandomDraw, FUN>>
325 mapping ([v](
size_t){
return v; });
333 Fun& thisMapping =
static_cast<Fun&
> (*this);
335 ,[theFun = forward<FUN> (fun)]
352 Fun& thisMapping =
static_cast<Fun&
> (*this);
365 static_assert (
_Fun(),
"Need something function-like.");
367 using Sig = _Fun::Sig;
368 using Args = _Fun::Args;
371 if constexpr (std::is_same_v<Args, BaseIn>)
373 return forward<FUN> (fun);
376 using Adaptor = POL::template Adaptor<Sig>;
377 return Adaptor::build (forward<FUN> (fun));
400 if constexpr (std::is_same_v<Res, Tar>)
401 return std::forward<FUN>(fun);
403 if constexpr (std::is_same_v<Res, size_t>)
404 return chained (std::forward<FUN>(fun)
408 if constexpr (std::is_same_v<Res, double>)
409 return chained (std::forward<FUN>(fun)
410 ,[
this](
double rand){
return limited(rand); }
413 if constexpr (std::is_same_v<Res, RandomDraw>)
414 return [functor=std::forward<FUN>(fun)]
415 (
auto&& ...inArgs) -> _FunRet<RandomDraw>
418 return adaptedDraw (forward<
decltype(inArgs)> (inArgs)...);
421 static_assert (not
sizeof(Res),
"unable to adapt / handle result type");
422 NOTREACHED(
"Handle based on return type");
Mix-in for lazy/delayed initialisation of an embedded functor.
void installInitialiser(std::function< SIG > &targetFunctor, INI &&initialiser)
A component and builder to draw limited parameter values based on some source of randomness (or hash ...
RandomDraw()
Drawing is disabled by default, always yielding "zero".
static constexpr size_t QUANTISER
double asRand(size_t hash)
RandomDraw && fixedVal(Tar v)
RandomDraw && shuffle(size_t seed=55)
RandomDraw && maxVal(Tar m)
RandomDraw(FUN &&fun)
Build a RandomDraw by attaching a value-processing function, which is adapted to accept the nominal i...
Tar drawLimited(size_t hash)
void installAdapted(FUN &&fun)
Lazy::MarkDisabled Disabled
RandomDraw && mapping(FUN &&fun)
Tar maxResult_
maximum result val actually to produce < max
RandomDraw && minVal(Tar m)
Tar minResult_
minimum result val actually to produce > min
RandomDraw && probability(double p)
double probability_
probability that value is in [min .. max] \ neutral
static constexpr double CAP_EPSILON
size_t shuffle_
statefull additional randomisation to inject into hash
double uni()
random double drawn from interval [0.0 ... 1.0[
Lumiera error handling (C interface).
Partial function application and building a complete function closure.
Metaprogramming tools for detecting and transforming function types.
Building block to allow delayed initialisation of infrastructure tied to a functor.
Implementation namespace for support and library code.
Random defaultGen
a global default RandomSequencer for mundane purposes
constexpr int ilog2(I num)
Integral binary logarithm (disregarding fractional part)
constexpr NUM limited(NB lowerBound, NUM val, NB upperBound)
force a numeric to be within bounds, inclusively
Generating (pseudo) random numbers with controlled seed.
A Result Value confined into fixed bounds.
static constexpr T minVal()
static constexpr T zeroVal()
static constexpr T maxVal()
Default policy for RandomDraw: generate limted-range random numbers.
static double defaultSrc()
Utilities for quantisation (grid alignment) and comparisons.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...