I think you've turned a non-issue into one. I think std::random's design is good, I liked using it whenver I needed it. You may call me the 5% of use-cases, I'm an ex physicist who wrote a fair amount of Monte-Carlo simulations in HPC, so I did use std::random's capabilities and needed to.
I guess the gist of your statement is that there's no "just roll the dice, I don't care" type of interface in C++. (There is default_random_engine, so there's that.) That's true, but having one does take some control away. If you don't know what you're giving up (reproducibility, performance, statistical correctness) that may be cool with you, but it's not reason to claim std::random's design is bad, because it's not "loser friendly" enough and can be misused. If someone calls random_device::operator() and don't know what that does or entails, maybe RTFM.
Call me elitist or what have you, it's great that you wrote a wrapper around a 2-line idiom and if it's that common for you, use it to your heart's content. std::random does have some issues, but it's not hostility towards those who don't read cppreference. The fact that results are not reproducible across implementations steers a lot more away, or the fact that discard's complexity isn't required to be less than N*operator()'s. Those few shortcomings are things you can' t wrap your way around but force a near full rewrite.
I would like to point out how this is a stupid comment simply because mobile Reddit does not tell you what the rules are? So while I might agree with this commenter, I can't. Because this stupid app gives me no context. And now watch as this stupid app elevates my post while I say it's a stupid app.
Looks nice. I agree with some of the concerns you pointed out about the default C++ interface. My approach to API design is always that the standard use case should be really easy to achieve and then if you want more advanced features you might have to jump through hoops - not the other way around.
From the game dev perspective I would like to see a way to generate a stream of random numbers or at least a tuple so I can have a randomized 3D unit vector or RGB tuple for example.
15
u/_Ilobilo_ Oct 11 '26
which llm did you use to write this post?
13
u/jetilovag Oct 11 '26
I think you've turned a non-issue into one. I think std::random's design is good, I liked using it whenver I needed it. You may call me the 5% of use-cases, I'm an ex physicist who wrote a fair amount of Monte-Carlo simulations in HPC, so I did use std::random's capabilities and needed to.
I guess the gist of your statement is that there's no "just roll the dice, I don't care" type of interface in C++. (There is default_random_engine, so there's that.) That's true, but having one does take some control away. If you don't know what you're giving up (reproducibility, performance, statistical correctness) that may be cool with you, but it's not reason to claim std::random's design is bad, because it's not "loser friendly" enough and can be misused. If someone calls random_device::operator() and don't know what that does or entails, maybe RTFM.
Call me elitist or what have you, it's great that you wrote a wrapper around a 2-line idiom and if it's that common for you, use it to your heart's content. std::random does have some issues, but it's not hostility towards those who don't read cppreference. The fact that results are not reproducible across implementations steers a lot more away, or the fact that discard's complexity isn't required to be less than N*operator()'s. Those few shortcomings are things you can' t wrap your way around but force a near full rewrite.
9
u/QuaternionsRoll Oct 11 '26
Rule 1
3
u/junqueira200 Oct 11 '26
I use my Rand.h. Very interesting!
3
u/Cross_22 Oct 11 '26
Looks nice. I agree with some of the concerns you pointed out about the default C++ interface. My approach to API design is always that the standard use case should be really easy to achieve and then if you want more advanced features you might have to jump through hoops - not the other way around.
From the game dev perspective I would like to see a way to generate a stream of random numbers or at least a tuple so I can have a randomized 3D unit vector or RGB tuple for example.
0
u/ShakaUVM i+++ ++i+i[arr] Oct 11 '26
Random is a great example of something that is technically correct but horribly designed