We are developing a compile-time random number generator.
In order to provide the seed, we coded a very simple constexpr
function that operates on the chars of __DATE__ and __TIME__.
However, I would like to improve this, e.g. by adding more accuracy.
This leads either to invent a long __EPOCH__-like macro with enough
precision (or a similar macro such as __MSECS_FROM_MIDNIGHT__) or a
built-in
compiler-implemented constexpr function, such as std::seed().
On Tuesday 17 November 2015 17:40:59 dgutson . wrote:
> > If you're forking GCC, you can add an intrinsic that can be called in that
> > constexpr context and returns a pseudo-random value of its own.
>
> Yes, that's one of the alternatives we are considering as the
> "compiler magic" version,
> though I'd like to see the frontend stadard first.
I don't think this could be standardised. We want reliable builds.
El 17/11/2015 20:15, "Nevin Liber" <ne...@cplusplusguy.com> escribió:
>
> On 17 November 2015 at 16:59, Thiago Macieira <thi...@macieira.org> wrote:
>>
>> On Tuesday 17 November 2015 17:40:59 dgutson . wrote:
>> > > If you're forking GCC, you can add an intrinsic that can be called in that
>> > > constexpr context and returns a pseudo-random value of its own.
>> >
>> > Yes, that's one of the alternatives we are considering as the
>> > "compiler magic" version,
>> > though I'd like to see the frontend stadard first.
>>
>> I don't think this could be standardised. We want reliable builds.
>
>
> I'm guessing you meant repeatable, not reliable. If so, I agree. If not, please elaborate.
What's the std definition of 'repeatable'? Does the std require to generate always the same binary?
>
> I'm also weary about the cryptographic applications of such a function/macro, as that is usually based on keeping something secret. And if Daniel cannot talk about it, it becomes that much harder to get support for the feature.
Ok I'll try. Let's suppose we have a production line for some mil application where for security reasons each binary has to be released in a way that if it gets hacked, other binaries (produced with the same code) don't get hacked by the same codes.
>
> As for the pivot selection of quicksort, why does having a constexpr seed generator particularly help (I suppose you could get a tiny bit of inlining performance when applying it to nearly sorted data, but I'd like to see benchmarks before drawing any conclusions)?
Because we are already able to have associative containers that are stored in ROM, which nontrivial constructors are executed in constexpr time, and some hashing functions that are also executed in constexpr contexts which also require RNG. I already started a thread in this list a couple of months ago where people suggested that current STL containers should be ROM friendly rather than a brand new category (such as static_unordered_map). We are already there but this will be a very lengthy paper.
>
> --
> Nevin ":-)" Liber <mailto:ne...@cplusplusguy.com> +1-847-691-1404
>
On Tue, Nov 17, 2015 at 12:08 PM, dgutson . <daniel...@gmail.com> wrote:We are developing a compile-time random number generator.
In order to provide the seed, we coded a very simple constexpr
function that operates on the chars of __DATE__ and __TIME__.
However, I would like to improve this, e.g. by adding more accuracy.
This leads either to invent a long __EPOCH__-like macro with enough
precision (or a similar macro such as __MSECS_FROM_MIDNIGHT__) or a
built-in compiler-implemented constexpr function, such as std::seed().
Compile-time random sounds pretty cool. I can think of a couple of uses, but I'm curious what your primary uses are.Regarding a compile-implemented constexpr function that produces a unique seed, I think you'd very quickly run into ODR issues unless you guaranteed that all translation units produced the same seed (i.e. you'd probably have to seed your seed via a macro or something). Have you considered just providing the seed directly from the outside via a compiler option, such as -D, and generating that seed via your build system? I realize that this is outside of the realm of the standard, but it's probably worth considering anyway. The facility would likely be just as useful in practice, unless I'm missing something.
So if you were to do:
constexpr int seed = __RANDOM__;
and include that header from two source files, you'd violate ODR.