digitalmars.D - Compile-Time RNG
- CTRNG (4/4) Jan 20 2016 I managed to create a compile-time random number generator.
- tsbockman (2/6) Jan 20 2016 That's clever (and devious).
- Timon Gehr (3/11) Jan 20 2016 It only works because compile-time introspection is ill-defined though.
- tsbockman (2/4) Jan 20 2016 That aspect can easily be replaced by __LINE__ and __FILE__.
- Matthias Bentrup (3/8) Jan 21 2016 A supported way to generate new names at compile time would be
- tsbockman (7/10) Jan 21 2016 It would, but in this particular case __LINE__ and __FILE__
- Era Scarecrow (4/11) Jan 21 2016 Hmm it does seem having an RNG during compile-time would be
- Brian Schott (4/8) Jan 20 2016 That's nearly as fun as using the bsr and bsf functions in
- Cym13 (8/12) Mar 05 2019 Sorry for necroposting but does anyone have that POC?
- Dennis (3/4) Mar 05 2019 It's on the D idioms list
- Stefan Koch (4/19) Mar 05 2019 it's easy. you use the time_stamp at compilation which is
- Cym13 (2/19) Mar 06 2019 Thank you both!
- Joseph Rushton Wakeling (5/8) Mar 07 2019 Depending on the use case, that might be problematic. Consider
- Stefan Koch (4/12) Mar 07 2019 Using that in any way that's not a toy example is ill'advised.
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.
Jan 20 2016
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.That's clever (and devious).
Jan 20 2016
On 01/21/2016 01:32 AM, tsbockman wrote:On Wednesday, 20 January 2016 at 23:21:04 UTC, CTRNG wrote:It only works because compile-time introspection is ill-defined though. I don't expect it to keep working indefinitely.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.That's clever (and devious).
Jan 20 2016
On Thursday, 21 January 2016 at 01:49:27 UTC, Timon Gehr wrote:It only works because compile-time introspection is ill-defined though. I don't expect it to keep working indefinitely.That aspect can easily be replaced by __LINE__ and __FILE__.
Jan 20 2016
On Thursday, 21 January 2016 at 07:43:13 UTC, tsbockman wrote:On Thursday, 21 January 2016 at 01:49:27 UTC, Timon Gehr wrote:A supported way to generate new names at compile time would be nice.It only works because compile-time introspection is ill-defined though. I don't expect it to keep working indefinitely.That aspect can easily be replaced by __LINE__ and __FILE__.
Jan 21 2016
On Thursday, 21 January 2016 at 09:29:38 UTC, Matthias Bentrup wrote:It would, but in this particular case __LINE__ and __FILE__ actually provide a more natural way of solving the problem. The idea of generating new symbols to increment the counter is clever, but it's also an awkward hack. __LINE__ already does pretty much what he needed by itself.That aspect can easily be replaced by __LINE__ and __FILE__.A supported way to generate new names at compile time would be nice.
Jan 21 2016
On Thursday, 21 January 2016 at 01:49:27 UTC, Timon Gehr wrote:On 01/21/2016 01:32 AM, tsbockman wrote:Hmm it does seem having an RNG during compile-time would be useful, although I'm trying to come up with a use-case for when it would actually work, or how you'd use it.On Wednesday, 20 January 2016 at 23:21:04 UTC, CTRNG wrote:It only works because compile-time introspection is ill-defined though. I don't expect it to keep working indefinitely.Just thought this might be of interest to some of you here.That's clever (and devious).
Jan 21 2016
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.That's nearly as fun as using the bsr and bsf functions in core.bitop to implement a pure random number generator. https://issues.dlang.org/show_bug.cgi?id=14380
Jan 20 2016
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).
Mar 05 2019
On Tuesday, 5 March 2019 at 21:22:55 UTC, Cym13 wrote:Sorry for necroposting but does anyone have that POC?It's on the D idioms list https://p0nce.github.io/d-idioms/#Compile-time-RNG
Mar 05 2019
On Tuesday, 5 March 2019 at 21:22:55 UTC, Cym13 wrote:On Wednesday, 20 January 2016 at 23:21:04 UTC, CTRNG 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.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).
Mar 05 2019
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:Thank you both!On Wednesday, 20 January 2016 at 23:21:04 UTC, CTRNG 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.[...]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).
Mar 06 2019
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.
Mar 07 2019
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:Using that in any way that's not a toy example is ill'advised. I'd say :)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.
Mar 07 2019