March 05
On Tuesday, 5 March 2019 at 21:22:55 UTC, Cym13 wrote:
> On Wednesday, 20 January 2016 at 23:21:04 UTC, CTRNG wrote:
>> I managed to create a compile-time random number generator.
>>
>> Proof of concept, with some explanatory comments: http://dpaste.dzfl.pl/668646ce6d71
>>
>> Just thought this might be of interest to some of you here.
>
> Sorry for necroposting but does anyone have that POC? dpaste.dzfl.pl seems down.
>
> I'm currently facing a case where I would very much like to have random data at compile-time and I can't find a way to get them.
>
> Also the core.bitopt.bsf bug mentionned later in the thread was fixed so no luck there (and the bug report is still open, I think it should be closed).

it's easy. you use the time_stamp at compilation which is expressed as a certain lexer variable. you parse that at ctfe and use it as the seed for another random number gen.
March 06
On Tuesday, 5 March 2019 at 22:57:31 UTC, Stefan Koch wrote:
> On Tuesday, 5 March 2019 at 21:22:55 UTC, Cym13 wrote:
>> On Wednesday, 20 January 2016 at 23:21:04 UTC, CTRNG wrote:
>>> [...]
>>
>> Sorry for necroposting but does anyone have that POC? dpaste.dzfl.pl seems down.
>>
>> I'm currently facing a case where I would very much like to have random data at compile-time and I can't find a way to get them.
>>
>> Also the core.bitopt.bsf bug mentionned later in the thread was fixed so no luck there (and the bug report is still open, I think it should be closed).
>
> it's easy. you use the time_stamp at compilation which is expressed as a certain lexer variable. you parse that at ctfe and use it as the seed for another random number gen.

Thank you both!
March 07
On Tuesday, 5 March 2019 at 22:57:31 UTC, Stefan Koch wrote:
> it's easy. you use the time_stamp at compilation which is expressed as a certain lexer variable. you parse that at ctfe and use it as the seed for another random number gen.

Depending on the use case, that might be problematic.  Consider two different compilation units issued in the same second (so same timestamp).  Both use the CTFE RNG, and because their seed is the same, so is the pseudo-random sequence.
March 07
On Thursday, 7 March 2019 at 09:53:58 UTC, Joseph Rushton Wakeling wrote:
> On Tuesday, 5 March 2019 at 22:57:31 UTC, Stefan Koch wrote:
>> it's easy. you use the time_stamp at compilation which is expressed as a certain lexer variable. you parse that at ctfe and use it as the seed for another random number gen.
>
> Depending on the use case, that might be problematic.  Consider two different compilation units issued in the same second (so same timestamp).  Both use the CTFE RNG, and because their seed is the same, so is the pseudo-random sequence.

Using that in any way that's not a toy example is ill'advised. I'd say :)

Next ›   Last »
1 2