www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - std.random:uniform - uncompilable example from docs

reply "Tyro[a.c.edwards]" <nospam home.com> writes:
http://www.digitalmars.com/d/2.0/phobos/std_random.html#uniform

Above documentation  provides the following example:

	Random gen(unpredictableSeed);
	// Generate an integer in [0, 1023]
	auto a = uniform(0, 1024, gen);
	// Generate a float in [0, 1)
	auto a = uniform(0.0f, 1.0f, gen);

Which, when complied, produces the following errors:

C:\Users\Andrew\code>dmd eds32
eds32.d(9): Error: function std.random.unpredictableSeed is used as a type
eds32.d(9): Error: cannot have parameter of type void
eds32.d(10): Error: function learn.eds32.randNum.gen (void) does not 
match parameter types ()
eds32.d(10): Error: expected 1 function arguments, not 0
eds32.d(10): Error: template std.random.uniform(immutable(char)[] 
boundaries = "[)",T1,T2,UniformRandomNumberGenerator) if 
(is(CommonType!(T1,UniformRandomNumberGenerator) == void) && 
!is(CommonType!(T1,T2) == void)) does not match any function template 
declaration
eds32.d(10): Error: template std.random.uniform(immutable(char)[] 
boundaries = "[)",T1,T2,UniformRandomNumberGenerator) if 
(is(CommonType!(T1,UniformRandomNumberGenerator) == void) && 
!is(CommonType!(T1,T2) == void)) cannot deduce template function from 
argument types !()(int,int,MersenneTwisterEngine!(uint,32,624,397,
31,-1727483681u,11,7,-1658038656u,15,-272236544u,18))

Suggest that the first line of the example be changed to:

	auto gen = Random(unpredictableSeed);

Or that a correctly working example be provided.

Andrew
May 09 2009
parent reply Christopher Wright <dhasenan gmail.com> writes:
Tyro[a.c.edwards] wrote:
 http://www.digitalmars.com/d/2.0/phobos/std_random.html#uniform
 
 Above documentation  provides the following example:
 
     Random gen(unpredictableSeed);
     // Generate an integer in [0, 1023]
     auto a = uniform(0, 1024, gen);
     // Generate a float in [0, 1)
     auto a = uniform(0.0f, 1.0f, gen);
 
 Which, when complied, produces the following errors:
It would be cool if DDoc could incorporate unittest examples -- it's in a doc comment and a unittest, changes automatically propagated between the two, so if your unittest succeeds, the documentation is probably at least somewhat correct.
May 10 2009
parent bearophile <bearophileHUGS lycos.com> writes:
Christopher Wright:
 It would be cool if DDoc could incorporate unittest examples -- it's in 
 a doc comment and a unittest, changes automatically propagated between 
 the two, so if your unittest succeeds, the documentation is probably at 
 least somewhat correct.
Having something like the Python doctests in D can be interesting. Bye, bearophile
May 10 2009