randomBatesSource function
Returns a randomBates function but where the given random number generator
source
is used as the source of randomness instead of Random.nextDouble.
The given random number generator must implement the same interface as Random.nextDouble and only return values in the range [0, 1). This is useful when a seeded random number generator is preferable to Random.nextDouble.
final seed = …; // any number in [0, 1)
final random = randomBatesSource(randomLcg(seed))(…);
Implementation
num Function() Function(num) randomBatesSource(num Function() source) {
var I = randomIrwinHallSource(source);
return (num n) {
// use limiting distribution at n == 0
if (n == 0) return source;
var randomIrwinHall = I(n);
return () {
return randomIrwinHall() / n;
};
};
}