I have this:
#include
using namespace std;
int main()
{
int a[256];
int b;
int k;
for (int i = 0; i < 256; i ++){
std::random_shuffle is the way to go, as previously mentioned, but just in case you don't want to use it (maybe using ANSI C instead of C++), here's a quick-and-dirty implementation:
#include
#include
#define SIZE 256
static inline void
swap(int *a, int *b) {
// Don't swap them if they happen to be the same element
// in the array, otherwise it'd be zeroed out
if (a != b) {
*a ^= *b;
*b ^= *a;
*a ^= *b;
}
}
int main(void)
{
int A[SIZE], i;
// Initialize array with sequential incrementing numbers
for (i = 0; i < SIZE; ++i)
A[i] = i;
// Initialize random seed
srand(time(NULL));
// Swap every element of the array with another random element
for (i = 0; i < SIZE; ++i)
swap(&A[i], &A[rand() % SIZE]);
return 0;
}