1 /* $OpenBSD: _rand48.c,v 1.3 2005/08/08 08:05:36 espie Exp $ */ 2 /* 3 * Copyright (c) 1993 Martin Birgmeier 4 * All rights reserved. 5 * 6 * You may redistribute unmodified or modified versions of this source 7 * code provided that the above copyright notice and this and the 8 * following conditions are retained. 9 * 10 * This software is provided ``as is'', and comes with no warranties 11 * of any kind. I shall in no event be liable for anything that happens 12 * to anyone/anything when using this software. 13 */ 14 15 #include "rand48.h" 16 17 unsigned short __rand48_seed[3] = { 18 RAND48_SEED_0, 19 RAND48_SEED_1, 20 RAND48_SEED_2 21 }; 22 unsigned short __rand48_mult[3] = { 23 RAND48_MULT_0, 24 RAND48_MULT_1, 25 RAND48_MULT_2 26 }; 27 unsigned short __rand48_add = RAND48_ADD; 28 29 void 30 __dorand48(unsigned short xseed[3]) 31 { 32 unsigned long accu; 33 unsigned short temp[2]; 34 35 accu = (unsigned long) __rand48_mult[0] * (unsigned long) xseed[0] + 36 (unsigned long) __rand48_add; 37 temp[0] = (unsigned short) accu; /* lower 16 bits */ 38 accu >>= sizeof(unsigned short) * 8; 39 accu += (unsigned long) __rand48_mult[0] * (unsigned long) xseed[1] + 40 (unsigned long) __rand48_mult[1] * (unsigned long) xseed[0]; 41 temp[1] = (unsigned short) accu; /* middle 16 bits */ 42 accu >>= sizeof(unsigned short) * 8; 43 accu += __rand48_mult[0] * xseed[2] + __rand48_mult[1] * xseed[1] + __rand48_mult[2] * xseed[0]; 44 xseed[0] = temp[0]; 45 xseed[1] = temp[1]; 46 xseed[2] = (unsigned short) accu; 47 } 48