Fix startup to security-relevant statically linked binaries.
[glibc.git] / stdlib / tst-rand48-2.c
blob3079b98839a8e9e107fe0116b106f92e29f3d3ae
1 #include <stdint.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <time.h>
6 int
7 main (void)
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];
16 srand48 ((long int) t);
17 for (i = 0; i < 50; i++)
18 if ((d = drand48 ()) < 0.0 || d >= 1.0)
20 printf ("drand48 %d %g\n", i, d);
21 ret = 1;
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)
28 printf ("drand48_r %d %g\n", i, d);
29 ret = 1;
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)
36 printf ("erand48 %d %g\n", i, d);
37 ret = 1;
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)
44 printf ("erand48_r %d %g\n", i, d);
45 ret = 1;
48 srand48 ((long int) t);
49 for (i = 0; i < 50; i++)
50 if ((l = lrand48 ()) < 0 || l > INT32_MAX)
52 printf ("lrand48 %d %ld\n", i, l);
53 ret = 1;
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)
60 printf ("lrand48_r %d %ld\n", i, l);
61 ret = 1;
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)
68 printf ("nrand48 %d %ld\n", i, l);
69 ret = 1;
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)
76 printf ("nrand48_r %d %ld\n", i, l);
77 ret = 1;
80 srand48 ((long int) t);
81 for (i = 0; i < 50; i++)
82 if ((l = mrand48 ()) < INT32_MIN || l > INT32_MAX)
84 printf ("mrand48 %d %ld\n", i, l);
85 ret = 1;
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)
92 printf ("mrand48_r %d %ld\n", i, l);
93 ret = 1;
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)
100 printf ("jrand48 %d %ld\n", i, l);
101 ret = 1;
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)
108 printf ("jrand48_r %d %ld\n", i, l);
109 ret = 1;
112 return ret;