D 程序中的语法是什么,它与 R 中的 set.seed ( 1234)" 相同

What is the syntax in D program which is the same of set.seed ( 1234)" in R

"srand "是错误的命令。这是我第一次使用 D 语言。 D as set.seed in R.

的代码是什么
void main() {
//srand(1234);  ????//
randInit();
auto x = RMatrix(10,1);foreach(rep; 0..1) {
printR(rep.robj);
double init = 0.0;
    foreach(ii; 0..100) {
        init = 0.5*init + rnorm();
    }
    x[0,0] = init;
    foreach(ii; 1..x.rows) {
        x[ii,0] = 0.8*x[ii-1,0] + rnorm();
    }

这取决于您使用的是什么库。如果你 import core.stdc.stdlib; 你可以做 randsrand 但最好的方法可能是使用 std.random.

你关心种子具体是什么吗?如果没有,你可以使用自动的,只调用一些随机函数:

// Generate a uniformly-distributed integer in the range [0, 14]
auto i = uniform(0, 15);

或者你自己看:

Random gen = Random(unpredictableSeed);
auto r = uniform(0.0L, 100.0L, gen);

如果您确实使用自己的 Random 对象,请务必通过 ref 将其传递给任何使用它的函数!

Random(unpredictableSeed) 类似于其他语言中的 srand(time())。您也可以 Random(1234) 使用特定的种子。

这些例子来自这里:http://dlang.org/phobos/std_random.html