shuffle function in c
#include <stdlib.h>
void shuffle(int arr[], int size){
srand(time(0));
for (int i = 0; i < size; i++) {
int j = rand() % size;
int t = arr[i];
arr[i] = arr[j];
arr[j] = t;
}
}
shuffle function in c
#include <stdlib.h>
void shuffle(int arr[], int size){
srand(time(0));
for (int i = 0; i < size; i++) {
int j = rand() % size;
int t = arr[i];
arr[i] = arr[j];
arr[j] = t;
}
}
how to shuffle array in c
#include <stdlib.h>
/* Arrange the N elements of ARRAY in random order.
Only effective if N is much smaller than RAND_MAX;
if this may not be the case, use a better random
number generator. */
void shuffle(int *array, size_t n)
{
if (n > 1)
{
size_t i;
for (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;
}
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us