Live data from Hacker News

The C++ community is polarized about C++11's random-number facility

pcg-random.org

31–40 of 67 posts

Re: The C++ community is polarized about C++11's random-number facility

#31

Earlier quoted context omitted.

You misunderstand me. I think random(3) should have been omitted from the C standard.

What happens if you don't provide sensible, easy-to-use built-in implementations of things is that a diverse, bewildering ecosystem of different options tends to arise, confusing programmers who just want to get their job done and leading to a high probability of them picking the wrong thing. See, for example, crypto before NaCl came around. (NB: I'm not defending either this C++ standard or random(3).)

I thought NaCl was something related to browser plugins. What is the connection with crypto?

Re: The C++ community is polarized about C++11's random-number facility

#32

Earlier quoted context omitted.

What happens if you don't provide sensible, easy-to-use built-in implementations of things is that a diverse, bewildering ecosystem of different options tends to arise, confusing programmers who just want to get their job done and leading to a high probability of them picking the wrong thing. See, for example, crypto before NaCl came around. (NB: I'm not defending either this C++ standard or random(3).)

I thought NaCl was something related to browser plugins. What is the connection with crypto?

Name collisions: http://nacl.cr.yp.to/

Although, I've never actually seen it used in the wild.

Re: The C++ community is polarized about C++11's random-number facility

#34
Tl;dr- clickbait title for a C++11 imitation of Pythons random-number facility

>In fact, anything that's easy to do with Python's RNG class is just as easy to do here—in designing the class, wanted random number generation in C++ to become as easy as it is in Python

>But don't just take my word for it, download randutils.hpp and play around. Start having actual fun with random number generation.

Re: The C++ community is polarized about C++11's random-number facility

#35
post #23

Earlier quoted context omitted.

Because Microsoft implemented random_device correctly while MingW / GCC hasn't? Its a bug in MingW. Which isn't a big deal because Microsoft Visual Studio Community Edition is an excellent IDE and compatible with OSS projects now.

Could you point to the gcc bug? Note: the standard does not require a non-deterministic random_device, at least C++11 doesn't, so the behaviour as described in the stackoverflow link would be allowed.

There are a lot of things the C and C++ standards allow implementations to do, such as making int 16 bits, using one's complement for signed integers, (in C) only making the first 31 characters of identifiers significant, (in C++) not allowing any identifiers longer than one character, except those in the standard library, et cetera. This is because they are designed to be portable to a wide variety of compilers and target devices which might have limits that weren't envisioned at the time of writing the standard. Doesn't mean it's a good idea to write absolutely pathological implementations for no real reason other than laziness...

Re: The C++ community is polarized about C++11's random-number facility

#36
post #35
post #23

Earlier quoted context omitted.

Could you point to the gcc bug? Note: the standard does not require a non-deterministic random_device, at least C++11 doesn't, so the behaviour as described in the stackoverflow link would be allowed.

There are a lot of things the C and C++ standards allow implementations to do, such as making int 16 bits, using one's complement for signed integers, (in C) only making the first 31 characters of identifiers significant, (in C++) not allowing any identifiers longer than one character, except those in the standard library, et cetera. This is because they are designed to be portable to a wide variety of compilers and…

>This is because they are designed to be portable to a wide variety of compilers and target devices which might have limits that weren't envisioned at the time of writing the standard.

That's not really the case here, is it? If anything the bug is in the standard.

Re: The C++ community is polarized about C++11's random-number facility

#37
post #33

Why not specify the algorithm for std::rand? The specification, as far as I'm aware, gives no guarantees at all about the algorithm used. Why not just specify a good algorithm instead of adding a new function?

std::rand has global state. Specifying the algorithm doesn't fix that.

And this lets you (easily) generate more than just integers in the range [0, INT_MAX]. std::rand doesn't have that level of convenience.

There are all sorts of inconveniences with std::rand, and it looks like this solves the vast majority of them.

Re: The C++ community is polarized about C++11's random-number facility

#38

One thing that I would like to have is a common base class that can be passed around. Often, I would like for a function orclass to be told which engine to use, quite useful for unit testing, or for having reproducible results. As it is, the only way to accept multiple different engines is by templating over the engine type. This ends up requiring that every part of the code that uses the random engine be brought int…

I kind of agree! But think about performance. A fast pseudo random generator will/should create a random number in less cycles than one virtual function call has overhead. Also it's not hard to create your own virtual random class if you are willing to pay the price.

Re: The C++ community is polarized about C++11's random-number facility

#39

"To the extent that anyone cares about C++11's random-number facility at all, the C++ community is polarized between two views—one that likes it, and one that hates it." Isn't that almost a tautology? "People who care about X either love it or hate it".

No. You can recognize the importance of something and care about it a lot while thinking it's (eg) mediocre. Thinking a problem is important and having an extreme opinion of a solution are entirely different axes.

Re: The C++ community is polarized about C++11's random-number facility

#40
post #33

Why not specify the algorithm for std::rand? The specification, as far as I'm aware, gives no guarantees at all about the algorithm used. Why not just specify a good algorithm instead of adding a new function?

They added more than a single new function. Personally, I like what was added. For what it's worth, I generally don't need to consult the documentation for the new random facilities (for a definition of "new" that includes "four years old"), but I do need to consult the docs for the stuff in .

> The specification, as far as I'm aware, gives no guarantees at all about the algorithm used.

You are right about that. And, in fact, the few guarantees the standard has are weak enough that Microsoft ships a standards compliant implementation that is famously limited.

Post reply on HN