Here's a possible way with a little example included about shuffling an array:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void shuffle(int *array, int n) {
srand((unsigned)time(NULL));
for (int i = 0; i < n - 1; i++) {
size_t j = i + rand() / (RAND_MAX / (n - i) + 1);
int t = array[j];
array[j] = array[i];
array[i] = t;
}
}
#define N 6
int main() {
int positions[N] = {0, 1, 2, 3, 4, 5};
for (int j = 0; j < 10; j++) {
shuffle(positions, N);
for (int x = 0; x < N; x++) printf("%d ", positions[x]);
printf("\n");
}
return 0;
}
The output:
2 5 3 1 0 4
3 4 1 5 2 0
1 0 5 4 3 2
5 2 4 0 1 3
4 3 0 2 5 1
0 1 2 3 4 5
2 5 3 1 0 4
3 4 1 5 2 0
1 0 5 4 3 2
5 2 4 0 1 3
Now, if we focus on your particular example, where you want to shuffle an array of random values with 15 zeroes, you just need to fill the array with positive integers first, then adding 15 zeroes, for instance in the first 15 positions and then shuffling the array as many times as you like, example below:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define WIDTH 15
#define HEIGHT 5
void shuffle(int *array, int n) {
srand((unsigned)time(NULL));
for (int i = 0; i < n - 1; i++) {
size_t j = i + rand() / (RAND_MAX / (n - i) + 1);
int t = array[j];
array[j] = array[i];
array[i] = t;
}
}
void fill_array(int *array, int height, int width) {
for (int y = 0; y < HEIGHT; y++) {
for (int x = 0; x < WIDTH; x++) {
int value = (rand() % 5) + 1;
array[y * width + x] = value;
}
}
for (int x = 0; x < WIDTH; x++) {
array[x] = 0;
}
}
void display_array(int *array, int height, int width) {
for (int y = 0; y < HEIGHT; y++) {
for (int x = 0; x < WIDTH; x++) {
printf("%d ", array[y * width + x]);
}
printf("\n");
}
}
int main() {
int array[WIDTH * HEIGHT];
fill_array(array, HEIGHT, WIDTH);
for (int j = 0; j < 10; j++) {
shuffle(array, HEIGHT * WIDTH);
}
display_array(array, HEIGHT, WIDTH);
return 0;
}
2 5 1 0 0 2 2 2 4 2 2 4 3 1 4
5 3 0 2 0 3 5 1 1 4 3 5 0 2 1
2 3 5 0 2 5 3 3 0 2 0 0 4 0 4
1 1 2 3 4 0 0 3 3 1 0 3 5 3 3
5 4 0 4 5 2 2 3 0 1 4 5 4 3 4