How to generate a random array in c

To generate a random array in C, you can use the rand() function along with a loop to assign random values to each element of the array. Here's an example code snippet:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main() {
    // Set the seed for the random number generator
    srand(time(0));

    // Define the size of the array
    int size = 10;

    // Create an array of integers
    int array[size];

    // Generate random values for each element of the array
    for (int i = 0; i < size; i++) {
        array[i] = rand();
    }

    // Print the array
    for (int i = 0; i < size; i++) {
        printf("%d ", array[i]);
    }

    return 0;
}

In this code, the srand(time(0)) line sets the seed for the random number generator based on the current time, ensuring different random values each time the program is run. The rand() function is then used to generate random numbers, which are assigned to each element of the array using a loop. Finally, another loop is used to print the values of the array.

Please note that the rand() function generates pseudo-random numbers, which means that the sequence of numbers generated may not be truly random. If you require a more secure or higher-quality random number generation, you may need to use a different method or library.