Why do I always get the same sequence of random numbers with rand()?

前端 未结 12 2423
忘了有多久
忘了有多久 2020-11-21 06:06

This is the first time I\'m trying random numbers with C (I miss C#). Here is my code:

int i, j = 0;
for(i = 0; i <= 10; i++) {
    j = rand();
    printf         


        
12条回答
  •  情话喂你
    2020-11-21 06:38

    None of you guys are answering his question.

    with this code i get the same sequance everytime the code but it generates random sequences if i add srand(/somevalue/) before the for loop . can someone explain why ?

    From what my professor has told me, it is used if you want to make sure your code is running properly and to see if there is something wrong or if you can change something.

提交回复
热议问题