简体   繁体   English

rand 函数 c args

[英]rand function c args

I have a multi task application based on DTW(Dynamic Time Wrapping) that has this code line:我有一个基于 DTW(动态时间包装)的多任务应用程序,它具有以下代码行:

void randPattern(int in[SIZE][SIZE]){
    int i,j;

    for(i=0; i<SIZE; i++){
        for(j=0; j<SIZE; j++){
            in[i][j] = abs(rand(23, 2, 100)%5000);
        }
    }
}

So, when i tried to compile with "arm-none-eabi-gcc" this returns:因此,当我尝试使用“arm-none-eabi-gcc”进行编译时,它会返回:

error: too many arguments to function 'rand'

What i can do to solve this message or what i can use instead this function.我可以做些什么来解决这个消息,或者我可以用什么来代替这个功能。 If someone have an explanation... Thanks for attention如果有人有解释...谢谢关注

As explained in this article from cplusplus.com , the rand function has the following prototype:正如cplusplus.com上的这篇文章所述rand函数具有以下原型:

int rand (void);

and you get an int between 0 and RAND_MAX .你会得到一个介于 0 和RAND_MAX之间的int You must pass no argument to the function.您不得向该函数传递任何参数。

By the way, don't forget to initialize the function at the begginning of your program by calling :顺便说一句,不要忘记在程序开始时通过调用来初始化函数:

srand (time(NULL));

If you need to choose a random element from an array, this question may be the right place to look for.如果您需要从数组中选择一个随机元素, 这个问题可能是寻找的正确地方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM