aboutsummaryrefslogtreecommitdiff
blob: 8b8fef4430971f5dd24300872c37209119d649c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

static int
do_test (void)
{
  time_t t = time (NULL);
  int i, ret = 0;
  double d;
  long int l;
  struct drand48_data data;
  unsigned short int buf[3];

  srand48 ((long int) t);
  for (i = 0; i < 50; i++)
    if ((d = drand48 ()) < 0.0 || d >= 1.0)
      {
        printf ("drand48 %d %g\n", i, d);
        ret = 1;
      }

  srand48_r ((long int) t, &data);
  for (i = 0; i < 50; i++)
    if (drand48_r (&data, &d) != 0 || d < 0.0 || d >= 1.0)
      {
        printf ("drand48_r %d %g\n", i, d);
        ret = 1;
      }

  buf[2] = (t & 0xffff0000) >> 16; buf[1] = (t & 0xffff); buf[0] = 0x330e;
  for (i = 0; i < 50; i++)
    if ((d = erand48 (buf)) < 0.0 || d >= 1.0)
      {
        printf ("erand48 %d %g\n", i, d);
        ret = 1;
      }

  buf[2] = (t & 0xffff0000) >> 16; buf[1] = (t & 0xffff); buf[0] = 0x330e;
  for (i = 0; i < 50; i++)
    if (erand48_r (buf, &data, &d) != 0 || d < 0.0 || d >= 1.0)
      {
        printf ("erand48_r %d %g\n", i, d);
        ret = 1;
      }

  srand48 ((long int) t);
  for (i = 0; i < 50; i++)
    if ((l = lrand48 ()) < 0 || l > INT32_MAX)
      {
        printf ("lrand48 %d %ld\n", i, l);
        ret = 1;
      }

  srand48_r ((long int) t, &data);
  for (i = 0; i < 50; i++)
    if (lrand48_r (&data, &l) != 0 || l < 0 || l > INT32_MAX)
      {
        printf ("lrand48_r %d %ld\n", i, l);
        ret = 1;
      }

  buf[2] = (t & 0xffff0000) >> 16; buf[1] = (t & 0xffff); buf[0] = 0x330e;
  for (i = 0; i < 50; i++)
    if ((l = nrand48 (buf)) < 0 || l > INT32_MAX)
      {
        printf ("nrand48 %d %ld\n", i, l);
        ret = 1;
      }

  buf[2] = (t & 0xffff0000) >> 16; buf[1] = (t & 0xffff); buf[0] = 0x330e;
  for (i = 0; i < 50; i++)
    if (nrand48_r (buf, &data, &l) != 0 || l < 0 || l > INT32_MAX)
      {
        printf ("nrand48_r %d %ld\n", i, l);
        ret = 1;
      }

  srand48 ((long int) t);
  for (i = 0; i < 50; i++)
    if ((l = mrand48 ()) < INT32_MIN || l > INT32_MAX)
      {
        printf ("mrand48 %d %ld\n", i, l);
        ret = 1;
      }

  srand48_r ((long int) t, &data);
  for (i = 0; i < 50; i++)
    if (mrand48_r (&data, &l) != 0 || l < INT32_MIN || l > INT32_MAX)
      {
        printf ("mrand48_r %d %ld\n", i, l);
        ret = 1;
      }

  buf[2] = (t & 0xffff0000) >> 16; buf[1] = (t & 0xffff); buf[0] = 0x330e;
  for (i = 0; i < 50; i++)
    if ((l = jrand48 (buf)) < INT32_MIN || l > INT32_MAX)
      {
        printf ("jrand48 %d %ld\n", i, l);
        ret = 1;
      }

  buf[2] = (t & 0xffff0000) >> 16; buf[1] = (t & 0xffff); buf[0] = 0x330e;
  for (i = 0; i < 50; i++)
    if (jrand48_r (buf, &data, &l) != 0 || l < INT32_MIN || l > INT32_MAX)
      {
        printf ("jrand48_r %d %ld\n", i, l);
        ret = 1;
      }

  return ret;
}

#define TEST_FUNCTION do_test ()
#include "../test-skeleton.c"