[Issue 5249] Strongly pure random generator
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Aug 30 04:33:07 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=5249
Joseph Rushton Wakeling <joseph.wakeling at webdrake.net> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |joseph.wakeling at webdrake.ne
| |t
--- Comment #5 from Joseph Rushton Wakeling <joseph.wakeling at webdrake.net> 2013-08-30 04:33:02 PDT ---
(In reply to comment #0)
> As pure functions become more and more common in D2 programs, I'd like to
> generate some random values inside them too. So I suggest to add to the
> std.random module a strongly pure function that keeps no state and generates
> random values.
It's theoretically possible for quite a few existing RNGs to have a much better
degree of purity.
If we consider the range interface, then we'd like to have:
enum bool empty = false;
auto front() @property @safe const pure nothrow {}
void popFront() @safe pure nothrow {}
Among the current challenges are that the existing design/use of RNGs means
that initialization cannot be assumed, so many (e.g. Mersenne Twister) have
conditions inside front, popFront, etc. which amount to
if (/* is not initialized */)
{
seed();
}
... which kills const (where desirable) and may have an impact on purity as
well.
Some RNGs also have internals which mitigate against @safe.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list