On 5/31/2012 9:40 PM, TJB wrote:
One more question, if I may. I noticed that I forgot to include the
set_seed function. The call to rnorm works the way I have called it, but
it must be using some default seed (its a random number generator).

I have tried including the set_seed function as follows:

import std.stdio;

extern (C) void set_seed(unsigned int, unsigned int);
extern (C) double rnorm(double, double);

void main() {
set_seed(0,77991);
foreach(i; 0 .. 100) {
writeln(myfunc(0.0, 1.0));
}
}

double myfunc(double a, double b) {
return rnorm(a, b);
}

I compile this the same way as you suggest, but now the compiler is
squealing at me with the following message:

$ dmd rnorm.d -L-L/usr/lob -L-lRmath -L-lm
rnorm.d(6): found 'int' when expecting ')'
rnorm.d(6): semicolon expected following function declaration
rnorm.d(6): Declaration expected, not ','

When I grep set_seed in Rmath.h I get:

$ grep set_seed Rmath.h
void set_seed(unsigned int, unsigned int);

So I think I have called it correctly. Any thoughts or suggestions?

Thanks, you have been so helpful!

TJB



D doesn't know anything about C's 'unsigned int'. You need to convert parameters to the equivalent in D, which would be uint.

 extern (C) void set_seed(unsigned int, unsigned int);

See the following page for more info on interfacing with C:

http://dlang.org/interfaceToC.html

Reply via email to