OK, but you picked defaults using somewhat intricate choices from numeric limits, so I thought that was part of the point.
Another thing though: with your hypothetical library, now the float and int, and int RNG classes have different engines, so now you need one seed per type of random number, as opposed to one seed for the engine. This isn't a minor nitpick: fixing the seed it a basic part of debugging that comes early on even for inexperienced programmers and now it's much harder.
I don't think this is a solvable problem: global state is convenient up to the point where it isn't. The "easy" RNG systems in other languages rely on global state.
I could get behind something like:
class random {
mt19937 engine;
uniform_real_distribution reals{0,1};
normal_distribution gauss{0,1};
public:
int randint(int low, int high){
return uniform_int_distribution(low, high)(engine);
}
double real(){
return reals(engine);
}
double gaussian(){
return gauss(engine);
}
// Other distributions why not
//Enough stuff to forward engine to the public interface so you
//can use it as an input to shuffle, and other, fnukier distributions
};
1
u/serviscope_minor Dec 21 '23
OK, but you picked defaults using somewhat intricate choices from numeric limits, so I thought that was part of the point.
Another thing though: with your hypothetical library, now the float and int, and int RNG classes have different engines, so now you need one seed per type of random number, as opposed to one seed for the engine. This isn't a minor nitpick: fixing the seed it a basic part of debugging that comes early on even for inexperienced programmers and now it's much harder.
I don't think this is a solvable problem: global state is convenient up to the point where it isn't. The "easy" RNG systems in other languages rely on global state.
I could get behind something like: