lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | #include <stdint.h> |
| 2 | #include <stdio.h> |
| 3 | #include <stdlib.h> |
| 4 | #include <time.h> |
| 5 | |
| 6 | static int |
| 7 | do_test (void) |
| 8 | { |
| 9 | time_t t = time (NULL); |
| 10 | int i, ret = 0; |
| 11 | double d; |
| 12 | long int l; |
| 13 | struct drand48_data data; |
| 14 | unsigned short int buf[3]; |
| 15 | |
| 16 | srand48 ((long int) t); |
| 17 | for (i = 0; i < 50; i++) |
| 18 | if ((d = drand48 ()) < 0.0 || d >= 1.0) |
| 19 | { |
| 20 | printf ("drand48 %d %g\n", i, d); |
| 21 | ret = 1; |
| 22 | } |
| 23 | |
| 24 | srand48_r ((long int) t, &data); |
| 25 | for (i = 0; i < 50; i++) |
| 26 | if (drand48_r (&data, &d) != 0 || d < 0.0 || d >= 1.0) |
| 27 | { |
| 28 | printf ("drand48_r %d %g\n", i, d); |
| 29 | ret = 1; |
| 30 | } |
| 31 | |
| 32 | buf[2] = (t & 0xffff0000) >> 16; buf[1] = (t & 0xffff); buf[0] = 0x330e; |
| 33 | for (i = 0; i < 50; i++) |
| 34 | if ((d = erand48 (buf)) < 0.0 || d >= 1.0) |
| 35 | { |
| 36 | printf ("erand48 %d %g\n", i, d); |
| 37 | ret = 1; |
| 38 | } |
| 39 | |
| 40 | buf[2] = (t & 0xffff0000) >> 16; buf[1] = (t & 0xffff); buf[0] = 0x330e; |
| 41 | for (i = 0; i < 50; i++) |
| 42 | if (erand48_r (buf, &data, &d) != 0 || d < 0.0 || d >= 1.0) |
| 43 | { |
| 44 | printf ("erand48_r %d %g\n", i, d); |
| 45 | ret = 1; |
| 46 | } |
| 47 | |
| 48 | srand48 ((long int) t); |
| 49 | for (i = 0; i < 50; i++) |
| 50 | if ((l = lrand48 ()) < 0 || l > INT32_MAX) |
| 51 | { |
| 52 | printf ("lrand48 %d %ld\n", i, l); |
| 53 | ret = 1; |
| 54 | } |
| 55 | |
| 56 | srand48_r ((long int) t, &data); |
| 57 | for (i = 0; i < 50; i++) |
| 58 | if (lrand48_r (&data, &l) != 0 || l < 0 || l > INT32_MAX) |
| 59 | { |
| 60 | printf ("lrand48_r %d %ld\n", i, l); |
| 61 | ret = 1; |
| 62 | } |
| 63 | |
| 64 | buf[2] = (t & 0xffff0000) >> 16; buf[1] = (t & 0xffff); buf[0] = 0x330e; |
| 65 | for (i = 0; i < 50; i++) |
| 66 | if ((l = nrand48 (buf)) < 0 || l > INT32_MAX) |
| 67 | { |
| 68 | printf ("nrand48 %d %ld\n", i, l); |
| 69 | ret = 1; |
| 70 | } |
| 71 | |
| 72 | buf[2] = (t & 0xffff0000) >> 16; buf[1] = (t & 0xffff); buf[0] = 0x330e; |
| 73 | for (i = 0; i < 50; i++) |
| 74 | if (nrand48_r (buf, &data, &l) != 0 || l < 0 || l > INT32_MAX) |
| 75 | { |
| 76 | printf ("nrand48_r %d %ld\n", i, l); |
| 77 | ret = 1; |
| 78 | } |
| 79 | |
| 80 | srand48 ((long int) t); |
| 81 | for (i = 0; i < 50; i++) |
| 82 | if ((l = mrand48 ()) < INT32_MIN || l > INT32_MAX) |
| 83 | { |
| 84 | printf ("mrand48 %d %ld\n", i, l); |
| 85 | ret = 1; |
| 86 | } |
| 87 | |
| 88 | srand48_r ((long int) t, &data); |
| 89 | for (i = 0; i < 50; i++) |
| 90 | if (mrand48_r (&data, &l) != 0 || l < INT32_MIN || l > INT32_MAX) |
| 91 | { |
| 92 | printf ("mrand48_r %d %ld\n", i, l); |
| 93 | ret = 1; |
| 94 | } |
| 95 | |
| 96 | buf[2] = (t & 0xffff0000) >> 16; buf[1] = (t & 0xffff); buf[0] = 0x330e; |
| 97 | for (i = 0; i < 50; i++) |
| 98 | if ((l = jrand48 (buf)) < INT32_MIN || l > INT32_MAX) |
| 99 | { |
| 100 | printf ("jrand48 %d %ld\n", i, l); |
| 101 | ret = 1; |
| 102 | } |
| 103 | |
| 104 | buf[2] = (t & 0xffff0000) >> 16; buf[1] = (t & 0xffff); buf[0] = 0x330e; |
| 105 | for (i = 0; i < 50; i++) |
| 106 | if (jrand48_r (buf, &data, &l) != 0 || l < INT32_MIN || l > INT32_MAX) |
| 107 | { |
| 108 | printf ("jrand48_r %d %ld\n", i, l); |
| 109 | ret = 1; |
| 110 | } |
| 111 | |
| 112 | return ret; |
| 113 | } |
| 114 | |
| 115 | #define TEST_FUNCTION do_test () |
| 116 | #include "../test-skeleton.c" |