summaryrefslogtreecommitdiff
path: root/gsl-1.9/doc/examples/permshuffle.c
diff options
context:
space:
mode:
Diffstat (limited to 'gsl-1.9/doc/examples/permshuffle.c')
-rw-r--r--gsl-1.9/doc/examples/permshuffle.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/gsl-1.9/doc/examples/permshuffle.c b/gsl-1.9/doc/examples/permshuffle.c
new file mode 100644
index 0000000..7247864
--- /dev/null
+++ b/gsl-1.9/doc/examples/permshuffle.c
@@ -0,0 +1,40 @@
+#include <stdio.h>
+#include <gsl/gsl_rng.h>
+#include <gsl/gsl_randist.h>
+#include <gsl/gsl_permutation.h>
+
+int
+main (void)
+{
+ const size_t N = 10;
+ const gsl_rng_type * T;
+ gsl_rng * r;
+
+ gsl_permutation * p = gsl_permutation_alloc (N);
+ gsl_permutation * q = gsl_permutation_alloc (N);
+
+ gsl_rng_env_setup();
+ T = gsl_rng_default;
+ r = gsl_rng_alloc (T);
+
+ printf ("initial permutation:");
+ gsl_permutation_init (p);
+ gsl_permutation_fprintf (stdout, p, " %u");
+ printf ("\n");
+
+ printf (" random permutation:");
+ gsl_ran_shuffle (r, p->data, N, sizeof(size_t));
+ gsl_permutation_fprintf (stdout, p, " %u");
+ printf ("\n");
+
+ printf ("inverse permutation:");
+ gsl_permutation_inverse (q, p);
+ gsl_permutation_fprintf (stdout, q, " %u");
+ printf ("\n");
+
+ gsl_permutation_free (p);
+ gsl_permutation_free (q);
+ gsl_rng_free (r);
+
+ return 0;
+}