Benny Prijono | e722461 | 2005-11-13 19:40:44 +0000 | [diff] [blame^] | 1 | /* $Id$
|
| 2 | */
|
| 3 | /*
|
| 4 | * PJLIB - PJ Foundation Library
|
| 5 | * (C)2003-2005 Benny Prijono <bennylp@bulukucing.org>
|
| 6 | *
|
| 7 | * Author:
|
| 8 | * Benny Prijono <bennylp@bulukucing.org>
|
| 9 | *
|
| 10 | * This library is free software; you can redistribute it and/or
|
| 11 | * modify it under the terms of the GNU Lesser General Public
|
| 12 | * License as published by the Free Software Foundation; either
|
| 13 | * version 2.1 of the License, or (at your option) any later version.
|
| 14 | *
|
| 15 | * This library is distributed in the hope that it will be useful,
|
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 18 | * Lesser General Public License for more details.
|
| 19 | *
|
| 20 | * You should have received a copy of the GNU Lesser General Public
|
| 21 | * License along with this library; if not, write to the Free Software
|
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
| 23 | */
|
| 24 | #include <pj/rand.h>
|
| 25 | #include <pj/log.h>
|
| 26 | #include "test.h"
|
| 27 |
|
| 28 | #if INCLUDE_RAND_TEST
|
| 29 |
|
| 30 | #define COUNT 1024
|
| 31 | static int values[COUNT];
|
| 32 |
|
| 33 | /*
|
| 34 | * rand_test(), simply generates COUNT number of random number and
|
| 35 | * check that there's no duplicate numbers.
|
| 36 | */
|
| 37 | int rand_test(void)
|
| 38 | {
|
| 39 | int i;
|
| 40 |
|
| 41 | for (i=0; i<COUNT; ++i) {
|
| 42 | int j;
|
| 43 |
|
| 44 | values[i] = pj_rand();
|
| 45 | for (j=0; j<i; ++j) {
|
| 46 | if (values[i] == values[j]) {
|
| 47 | PJ_LOG(3,("test", "error: duplicate value %d at %d-th index",
|
| 48 | values[i], i));
|
| 49 | return -10;
|
| 50 | }
|
| 51 | }
|
| 52 | }
|
| 53 |
|
| 54 | return 0;
|
| 55 | }
|
| 56 |
|
| 57 | #endif /* INCLUDE_RAND_TEST */
|
| 58 |
|