www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Compile-Time RNG

reply CTRNG <ctrng example.com> writes:
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
next sibling parent reply tsbockman <thomas.bockman gmail.com> writes:
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
parent reply Timon Gehr <timon.gehr gmx.ch> writes:
On 01/21/2016 01:32 AM, tsbockman 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.
That's clever (and devious).
It only works because compile-time introspection is ill-defined though. I don't expect it to keep working indefinitely.
Jan 20
next sibling parent reply tsbockman <thomas.bockman gmail.com> writes:
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
parent reply Matthias Bentrup <matthias.bentrup googlemail.com> writes:
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:
 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__.
A supported way to generate new names at compile time would be nice.
Jan 21
parent tsbockman <thomas.bockman gmail.com> writes:
On Thursday, 21 January 2016 at 09:29:38 UTC, Matthias Bentrup 
wrote:
 That aspect can easily be replaced by __LINE__ and __FILE__.
A supported way to generate new names at compile time would be nice.
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.
Jan 21
prev sibling parent Era Scarecrow <rtcvb32 yahoo.com> writes:
On Thursday, 21 January 2016 at 01:49:27 UTC, Timon Gehr wrote:
 On 01/21/2016 01:32 AM, tsbockman wrote:
 On Wednesday, 20 January 2016 at 23:21:04 UTC, CTRNG wrote:
 Just thought this might be of interest to some of you here.
That's clever (and devious).
It only works because compile-time introspection is ill-defined though. I don't expect it to keep working indefinitely.
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.
Jan 21
prev sibling parent Brian Schott <briancschott gmail.com> writes:
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