summaryrefslogtreecommitdiff
path: root/pjlib/src/pjlib-test/rand.c
diff options
context:
space:
mode:
Diffstat (limited to 'pjlib/src/pjlib-test/rand.c')
-rw-r--r--pjlib/src/pjlib-test/rand.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/pjlib/src/pjlib-test/rand.c b/pjlib/src/pjlib-test/rand.c
new file mode 100644
index 00000000..25f7a47e
--- /dev/null
+++ b/pjlib/src/pjlib-test/rand.c
@@ -0,0 +1,43 @@
+/* $Header: /pjproject-0.3/pjlib/src/pjlib-test/rand.c 1 10/05/05 5:13p Bennylp $ */
+/*
+ * $Log: /pjproject-0.3/pjlib/src/pjlib-test/rand.c $
+ *
+ * 1 10/05/05 5:13p Bennylp
+ * Created.
+ *
+ */
+#include <pj/rand.h>
+#include <pj/log.h>
+#include "test.h"
+
+#if INCLUDE_RAND_TEST
+
+#define COUNT 1024
+static int values[COUNT];
+
+/*
+ * rand_test(), simply generates COUNT number of random number and
+ * check that there's no duplicate numbers.
+ */
+int rand_test(void)
+{
+ int i;
+
+ for (i=0; i<COUNT; ++i) {
+ int j;
+
+ values[i] = pj_rand();
+ for (j=0; j<i; ++j) {
+ if (values[i] == values[j]) {
+ PJ_LOG(3,("test", "error: duplicate value %d at %d-th index",
+ values[i], i));
+ return -10;
+ }
+ }
+ }
+
+ return 0;
+}
+
+#endif /* INCLUDE_RAND_TEST */
+