A D wrapper over Gretl's random number generators. Currently (05/29/2020) avoids any dependencies on other libraries so it's independent of those design decisions. Those functions will be provided in a different module.
- Must call
randInitbefore calling any of these functions. - Should call
randFreeto clean up when you're done.
void randInit()
void randFree()
- Set and get the seed with
setSeedandgetSeed. Should normally do this to ensure replicability.setSeedrequires auinton the C side. Since this is a rarely called function,to!uintis used to convert the value for convenience. Note that this operation is safe.toconfirms that the values are within the acceptable range and throws an exception if not.
void setSeed(long seed)
uint getSeed()
uniformIntreturns one integer over the full range of acceptableintvalues (0through2^31 - 1) if no argument is provided.uniformIntreturns an integer less than the argument when called with an argument.
uint uniformInt(uint k) {
return gretl_rand_int_max(k);
}
runifreturns one double between 0 and 1 if called without an argument.runifreturns a double array ofnelements if called with an argument.runifUnsafeshould normally not be called. It is used by other library functions generating arrays of uniform values.
double runif()
double[] runif(int n, double min=0.0, double max=1.0)
void ruinfUnsafe(double * ptr, int len, double min=0.0, double max=1.0)