Experimental approach to reference-type random number generators
Joseph Rushton Wakeling
joseph.wakeling at webdrake.net
Sat Aug 24 11:35:48 PDT 2013
Hello all,
Today I spent some time playing around with an attempt at a wrapper for random
number generation. The idea is that random number generators should exist as
reference types, but without needing to be implemented as classes.
The basic wrapper is here: http://codepad.org/AlhLJa6A
And a partial port of std.random using the new wrapper is here:
http://codepad.org/SEBYMns6
See e.g. lines 392-394 and 666-670 for how the wrapper interacts with the random
number engines.
The basic idea seems to work, and with minimal overhead (it may even be slightly
faster in some scenarios). A few of the unittests have had to be commented out
(e.g. an opEquals needs to be implemented for the wrapper).
It looks promising to me, so before I go further I thought I'd open it up for
review and commentary.
Some of the features, e.g. the need for the engine to be initialized, may
explain some of my earlier questions on the mailing lists today ... :-)
I do have one specific query, about whether the way that .save is implemented
for the wrapper could leak memory given the fact that RefCounted is passed the
template parameter RefCountedAutoInitialize.yes.
Apart from that, {enj, destr}oy. Does this look like a valid route to a
next-gen std.random? :-)
Best wishes,
-- Joe
More information about the Digitalmars-d
mailing list