Skip to content
Browse files

C (or C++) version of the Simple example, already in Haskell

  • Loading branch information...
1 parent a8742cf commit cee7b559e2d7ec477196bf7a021f6750dc49a30c @bjpop committed Apr 8, 2011
Showing with 40 additions and 0 deletions.
  1. +40 −0 examples/Simple.cpp
View
40 examples/Simple.cpp
@@ -0,0 +1,40 @@
+#include "sprng.h"
+#include "sprng_cpp.h"
+
+void printRandInts(Sprng *rng, int num)
+{
+ int i;
+ rng->print_sprng();
+ for (i = 0; i < num; i++)
+ {
+ printf ("%d\n", rng->isprng());
+ }
+}
+
+void printRandDoubles(Sprng *rng, int num)
+{
+ int i;
+ rng->print_sprng();
+ for (i = 0; i < num; i++)
+ {
+ printf ("%.16lf\n", rng->sprng());
+ }
+}
+
+int main (void)
+{
+ int seed = 42;
+ Sprng * gen1, **gens;
+ gen1 = SelectType(SPRNG_LFG);
+ gen1->init_sprng(0, 1, seed, 0);
+ gen1->spawn_sprng(3, &gens);
+ printRandInts(gen1, 10);
+ printRandDoubles(gen1, 10);
+ printRandInts(gens[0], 10);
+ printRandDoubles(gens[0], 10);
+ printRandInts(gens[1], 10);
+ printRandDoubles(gens[1], 10);
+ printRandInts(gens[2], 10);
+ printRandDoubles(gens[2], 10);
+ return 0;
+}

0 comments on commit cee7b55

Please sign in to comment.
Something went wrong with that request. Please try again.