A Tausworthe random number generator

bearophile bearophileHUGS at lycos.com
Tue Jan 21 04:32:41 PST 2014


terchestor:

> https://github.com/Terchestor/dlang/tree/Tausworthe-class
>
> Please be indulgent ,-)

> /++
> §§§ Tausworthe

What's the purpose of those §? They add noise. If they aren't 
necessary I suggest to remove them.


> class Tausworthe ( I, F ) if ( __traits(isIntegral, I ) &&
>                                __traits(isFloating, F ) )

I suggest to not put spaces around ( ). And if you want also 
remove the space after the class/functions name.

Perhaps you want to use a struct? The decision is important. Are 
your methods all virtual?


> {
>     alias I integral_t;
>     alias F floating_t;

Today the syntax "alias Name = Foo;" is preferred.

In D code the use of "_t" as suffix for types is less common. And 
perhaps it's better to use a starting upper case letter for their 
name.


>     enum tauswortheConstFloat : floating_t
>     {
>         tau0 = 4294967296.0f

Class/struct/Enum/Union names should start with an upper case 
letter.


>          tau1 = 4294967294,

Perhaps that literal can end with a U.


>    ~this( )
>     { }

No need for this.


>     void seed( integral_t seed_=1 )
> ...
>         auto s = seed_;

In general annotate with enum/const/immutable all variables that 
don't need to mutate.


>         integral_t fseed( const integral_t s_ )
>         {
>             return ( tauswortheConst.lgc * s_ ) & 
> tauswortheConst.mask;
>         }

That's probably better annotated as pure nothrow.


> }//§§==========END_CLASS::Tausworthe==========

I suggest to reduce the amount of === in this code.


> auto ?tausworthe0 = new Tausworthe!(ulong, double);

While D supports Unicode identifiers, they are a often a pain in 
the ass (this is a personal opinion), so perhaps you want to kill 
them all.


> //§§ __COPYRIGHT_NOTICE__

I think there's a ddoc field syntax for the copyright in the 
module ddoc.

Bye,
bearophile


More information about the Digitalmars-d mailing list