1 /* $NetBSD: _rand48.c,v 1.7 2005/06/12 05:21:27 lukem Exp $ */
4 * Copyright (c) 1993 Martin Birgmeier
7 * You may redistribute unmodified or modified versions of this source
8 * code provided that the above copyright notice and this and the
9 * following conditions are retained.
11 * This software is provided ``as is'', and comes with no warranties
12 * of any kind. I shall in no event be liable for anything that happens
13 * to anyone/anything when using this software.
16 #include <sys/cdefs.h>
17 #if defined(LIBC_SCCS) && !defined(lint)
18 __RCSID("$NetBSD: _rand48.c,v 1.7 2005/06/12 05:21:27 lukem Exp $");
19 #endif /* LIBC_SCCS and not lint */
25 unsigned short __rand48_seed
[3] = {
30 unsigned short __rand48_mult
[3] = {
35 unsigned short __rand48_add
= RAND48_ADD
;
38 __dorand48(unsigned short xseed
[3])
41 unsigned short temp
[2];
43 _DIAGASSERT(xseed
!= NULL
);
45 accu
= (unsigned long) __rand48_mult
[0] * (unsigned long) xseed
[0] +
46 (unsigned long) __rand48_add
;
47 temp
[0] = (unsigned short) accu
; /* lower 16 bits */
48 accu
>>= sizeof(unsigned short) * 8;
49 accu
+= (unsigned long) __rand48_mult
[0] * (unsigned long) xseed
[1] +
50 (unsigned long) __rand48_mult
[1] * (unsigned long) xseed
[0];
51 temp
[1] = (unsigned short) accu
; /* middle 16 bits */
52 accu
>>= sizeof(unsigned short) * 8;
53 accu
+= __rand48_mult
[0] * xseed
[2] + __rand48_mult
[1] * xseed
[1] + __rand48_mult
[2] * xseed
[0];
56 xseed
[2] = (unsigned short) accu
;