diff options
Diffstat (limited to 'src/lib/libc/stdlib/_rand48.c')
-rw-r--r-- | src/lib/libc/stdlib/_rand48.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/lib/libc/stdlib/_rand48.c b/src/lib/libc/stdlib/_rand48.c new file mode 100644 index 0000000000..fed7372f68 --- /dev/null +++ b/src/lib/libc/stdlib/_rand48.c | |||
@@ -0,0 +1,50 @@ | |||
1 | /* | ||
2 | * Copyright (c) 1993 Martin Birgmeier | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * You may redistribute unmodified or modified versions of this source | ||
6 | * code provided that the above copyright notice and this and the | ||
7 | * following conditions are retained. | ||
8 | * | ||
9 | * This software is provided ``as is'', and comes with no warranties | ||
10 | * of any kind. I shall in no event be liable for anything that happens | ||
11 | * to anyone/anything when using this software. | ||
12 | */ | ||
13 | |||
14 | #if defined(LIBC_SCCS) && !defined(lint) | ||
15 | static char rcsid[] = "$OpenBSD: _rand48.c,v 1.2 1996/08/19 08:33:19 tholo Exp $"; | ||
16 | #endif /* LIBC_SCCS and not lint */ | ||
17 | |||
18 | #include "rand48.h" | ||
19 | |||
20 | unsigned short __rand48_seed[3] = { | ||
21 | RAND48_SEED_0, | ||
22 | RAND48_SEED_1, | ||
23 | RAND48_SEED_2 | ||
24 | }; | ||
25 | unsigned short __rand48_mult[3] = { | ||
26 | RAND48_MULT_0, | ||
27 | RAND48_MULT_1, | ||
28 | RAND48_MULT_2 | ||
29 | }; | ||
30 | unsigned short __rand48_add = RAND48_ADD; | ||
31 | |||
32 | void | ||
33 | __dorand48(unsigned short xseed[3]) | ||
34 | { | ||
35 | unsigned long accu; | ||
36 | unsigned short temp[2]; | ||
37 | |||
38 | accu = (unsigned long) __rand48_mult[0] * (unsigned long) xseed[0] + | ||
39 | (unsigned long) __rand48_add; | ||
40 | temp[0] = (unsigned short) accu; /* lower 16 bits */ | ||
41 | accu >>= sizeof(unsigned short) * 8; | ||
42 | accu += (unsigned long) __rand48_mult[0] * (unsigned long) xseed[1] + | ||
43 | (unsigned long) __rand48_mult[1] * (unsigned long) xseed[0]; | ||
44 | temp[1] = (unsigned short) accu; /* middle 16 bits */ | ||
45 | accu >>= sizeof(unsigned short) * 8; | ||
46 | accu += __rand48_mult[0] * xseed[2] + __rand48_mult[1] * xseed[1] + __rand48_mult[2] * xseed[0]; | ||
47 | xseed[0] = temp[0]; | ||
48 | xseed[1] = temp[1]; | ||
49 | xseed[2] = (unsigned short) accu; | ||
50 | } | ||