summaryrefslogtreecommitdiff
path: root/gsl-1.9/doc/examples/randwalk.c
diff options
context:
space:
mode:
Diffstat (limited to 'gsl-1.9/doc/examples/randwalk.c')
-rw-r--r--gsl-1.9/doc/examples/randwalk.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/gsl-1.9/doc/examples/randwalk.c b/gsl-1.9/doc/examples/randwalk.c
new file mode 100644
index 0000000..588aa50
--- /dev/null
+++ b/gsl-1.9/doc/examples/randwalk.c
@@ -0,0 +1,29 @@
+#include <stdio.h>
+#include <gsl/gsl_rng.h>
+#include <gsl/gsl_randist.h>
+
+int
+main (void)
+{
+ int i;
+ double x = 0, y = 0, dx, dy;
+
+ const gsl_rng_type * T;
+ gsl_rng * r;
+
+ gsl_rng_env_setup();
+ T = gsl_rng_default;
+ r = gsl_rng_alloc (T);
+
+ printf ("%g %g\n", x, y);
+
+ for (i = 0; i < 10; i++)
+ {
+ gsl_ran_dir_2d (r, &dx, &dy);
+ x += dx; y += dy;
+ printf ("%g %g\n", x, y);
+ }
+
+ gsl_rng_free (r);
+ return 0;
+}