digitalmars.D - A strongly pure PRNG
- Kagamin (2/2) Jan 07 2014 I believe, bearophile was interested in this - a strongly pure
- qznc (4/6) Jan 07 2014 I would consider this weakly pure, because the implicit parameter
- Joseph Rushton Wakeling (7/9) Jan 07 2014 Related -- the work I've been doing on an updated std.random:
- deadalnix (2/8) Jan 07 2014 Without this, http://dilbert.com/strips/comic/2001-10-25/
- Joseph Rushton Wakeling (11/12) Jan 08 2014 I guess you could do a design where you pass an immutable RNG state, and...
- monarch_dodra (5/15) Jan 08 2014 Nice :)
- Kagamin (2/8) Jan 11 2014 Formally it is immutable, see line 36.
- David Nadlinger (4/5) Jan 11 2014 Well, by breaking the type system you can make every PRNG
- Kagamin (4/4) Jan 11 2014 Only the cast breaks the type system, I go through holes. It's
- Joseph Rushton Wakeling (7/10) Jan 11 2014 That depends on your concept of a PRNG. Strictly speaking it can/should...
- bearophile (5/6) Jan 07 2014 The ER:
I believe, bearophile was interested in this - a strongly pure immutable Xorshift32(1) PRNG: http://dpaste.dzfl.pl/5f710daf
Jan 07 2014
On Tuesday, 7 January 2014 at 12:32:23 UTC, Kagamin wrote:I believe, bearophile was interested in this - a strongly pure immutable Xorshift32(1) PRNG: http://dpaste.dzfl.pl/5f710dafI would consider this weakly pure, because the implicit parameter "this" is not immutable. A strongly pure PRNG cannot change internal state.
Jan 07 2014
On 07/01/14 13:37, qznc wrote:I would consider this weakly pure, because the implicit parameter "this" is not immutable. A strongly pure PRNG cannot change internal state.Related -- the work I've been doing on an updated std.random: https://github.com/WebDrake/std.random2/blob/master/std/random2/generator.d It's easy to make class-based PRNGs weakly pure and const (i.e. pure in everything bar perhaps some of the seed functions, const apart from seed functions and popFront). I don't think it'd meed the criteria of a very strict functional-programming interpretation of purity, though.
Jan 07 2014
On Tuesday, 7 January 2014 at 12:37:39 UTC, qznc wrote:On Tuesday, 7 January 2014 at 12:32:23 UTC, Kagamin wrote:Without this, http://dilbert.com/strips/comic/2001-10-25/I believe, bearophile was interested in this - a strongly pure immutable Xorshift32(1) PRNG: http://dpaste.dzfl.pl/5f710dafI would consider this weakly pure, because the implicit parameter "this" is not immutable. A strongly pure PRNG cannot change internal state.
Jan 07 2014
On 08/01/14 02:13, deadalnix wrote:Without this, http://dilbert.com/strips/comic/2001-10-25/I guess you could do a design where you pass an immutable RNG state, and you get back whatever random number you ask for plus a new immutable state (perhaps provided via an out parameter). It's just that in this case it puts the responsibility on the user to be really careful in ensuring that the RNG state is passed around properly (the main PITA being getting back the updated state rather than passing the current one). It's really much easier to do it as a class which updates internal state, and where you can apply safe pure nothrow and (with obvious exceptions) const to just about every method; and I don't really see what you lose in a practical sense by doing it this way.
Jan 08 2014
On Wednesday, 8 January 2014 at 01:13:12 UTC, deadalnix wrote:On Tuesday, 7 January 2014 at 12:37:39 UTC, qznc wrote:Nice :) Of course, mandatory xkcd PRNG: https://d.puremagic.com/issues/show_bug.cgi?id=11138 You know, it *is* pure...On Tuesday, 7 January 2014 at 12:32:23 UTC, Kagamin wrote:Without this, http://dilbert.com/strips/comic/2001-10-25/I believe, bearophile was interested in this - a strongly pure immutable Xorshift32(1) PRNG: http://dpaste.dzfl.pl/5f710dafI would consider this weakly pure, because the implicit parameter "this" is not immutable. A strongly pure PRNG cannot change internal state.
Jan 08 2014
On Tuesday, 7 January 2014 at 12:37:39 UTC, qznc wrote:On Tuesday, 7 January 2014 at 12:32:23 UTC, Kagamin wrote:Formally it is immutable, see line 36.I believe, bearophile was interested in this - a strongly pure immutable Xorshift32(1) PRNG: http://dpaste.dzfl.pl/5f710dafI would consider this weakly pure, because the implicit parameter "this" is not immutable. A strongly pure PRNG cannot change internal state.
Jan 11 2014
On Saturday, 11 January 2014 at 10:19:00 UTC, Kagamin wrote:Formally it is immutable, see line 36.Well, by breaking the type system you can make every PRNG immutable. ;) David
Jan 11 2014
Only the cast breaks the type system, I go through holes. It's just a joke, purity and immutability are valued for their deterministic traits, so a random number generator is the last thing one would want to make pure or immutable.
Jan 11 2014
On 11/01/14 15:12, Kagamin wrote:Only the cast breaks the type system, I go through holes. It's just a joke, purity and immutability are valued for their deterministic traits, so a random number generator is the last thing one would want to make pure or immutable.That depends on your concept of a PRNG. Strictly speaking it can/should consist of (i) an immutable state (ii) a pure function that takes as input the current immutable state and returns a new immutable state. In practice, of course, it's almost invariably easier to implement this as a type that has mutable internal state.
Jan 11 2014
Kagamin:I believe, bearophile was interested in thisThe ER: https://d.puremagic.com/issues/show_bug.cgi?id=5249 Bye, bearophile
Jan 07 2014