M
M
Muriam2019-04-08 06:33:47
C++ / C#
Muriam, 2019-04-08 06:33:47

Why, when compiling a random array, with each subsequent compilation and run, the same numbers are displayed, and new ones are not generated?

#include <iostream>
#include <cstdlib>
#include <locale>
#include <conio.h>
#define SIZE 10

using namespace std;


void random_array(int array[SIZE]);

int main() 
{
    setlocale(LC_ALL, "rus");
    
    int array[SIZE];
    
    random_array(array);
     
    getch();
    return 0;
}

void random_array(int array[SIZE])
{
    cout << "массив случайных чисел" << endl;
    for (int i=0; i<SIZE; i++) 
    {
        array[i] = rand()%100;
        cout << array[i] << " ";
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SerJook, 2019-04-08
@Muriam

Add to the top of the main function:
srand(time(0));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question