0
Follow
1
View

How do you get rand to print multiple different numbers at once

csf211289 注册会员
2023-01-26 10:02

Put the set random number seed srand outside the loop

#include 
#include 
#define seconds 10
int main()
{
    srand(time(NULL));
    for (int i = 0; i <= seconds; i++)
    {
        int  r = rand() % 100;
        printf("process %d is done after sleeping for %d seconds", r, i);
        printf("\n");
    }
    return 0;
}
 

About the Author

Question Info

Publish Time
2023-01-26 10:02
Update Time
2023-01-26 10:02