X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fcfg%2Fmacros.h;h=abf2057d5308d43d56593d60d0d8ed2c642ac5c4;hb=5d5cb6250eacac50a8a587296e109c787764f5b8;hp=69c404851c14b107709b3e7f8e3bfe6ac66049dc;hpb=0eeba5822b3ff0e76ae0fd0272536d371d272d7d;p=bertos.git diff --git a/bertos/cfg/macros.h b/bertos/cfg/macros.h index 69c40485..abf2057d 100644 --- a/bertos/cfg/macros.h +++ b/bertos/cfg/macros.h @@ -126,6 +126,19 @@ #endif /* COMPILER_TYPEOF */ +/** + * Shuffle the content of \a array that counts \a len elements. + */ +#define SHUFFLE(array, len) \ + do { \ + int i, j; \ + for (i = (len) - 1; i > 0; i--) \ + { \ + j = ((i + 1) * (rand() / (RAND_MAX + 1.0))); \ + SWAP((array)[i], (array)[j]); \ + } \ + } while (0) + /** * Macro to swap \a a with \a b, with explicit type \a T for dumb C89 compilers. *