--- /dev/null
+/*
+ * Configuration; Modify as necessary
+ */
+var possibilities = 4;
+var maxloops = 10000;
+
+/*
+ * Variables
+ */
+var results = [], found = [];
+var total, loop, i, rnd, found_total;
+
+/*
+ * Returns a random number between 0 and possibilities - 1
+ */
+function random_possibility()
+{
+
+ return Math.floor(Math.random() * possibilities);
+}
+
+/*
+ * To get reasonable statistics, sample maxloops times
+ */
+for (loop = 0; loop < maxloops; loop++) {
+
+ /*
+ * Flag all possibilities as unprocessed, as well as our processed
+ * possibilities counter which we'll use as optimization
+ */
+ for (i = 0; i < possibilities; i++)
+ found[i] = false;
+ found_total = 0;
+
+ /*
+ * Loop indefinitely increasing total from zero
+ */
+ for (total = 0; ; total++) {
+ rnd = random_possibility();
+ if (!found[rnd]) {
+ /*
+ * New unprocessed possibility occured, flag as such
+ * and increase our processed possibilities by one.
+ * Then verify if our counter reached the number of
+ * possibilities, in which case they all were
+ * satisfied. We then record/mark a point in our
+ * sparse results array and break this innner loop.
+ */
+ found[rnd] = true;
+ if (++found_total == possibilities) {
+ if (results[total] == undefined)
+ results[total] = 0;
+ results[total]++;
+ break;
+ }
+ }
+ }
+
+}
+
+/*
+ * For every existing result, print its score
+ */
+stdout.write("Iterat.\t= Frequency:\n");
+for (total = results.length, i = 0; i < total; i++) {
+ if (results[i] != undefined)
+ stdout.write((i + 1) + "\t= " + results[i] + "\n");
+}
+
+/*
+ * XXX TODO XXX
+ * - It would be nice to automatically create a graphic with the results
+ */