13016Swollman/* 23016Swollman * Copyright (c) 1993 Martin Birgmeier 33016Swollman * All rights reserved. 43016Swollman * 53016Swollman * You may redistribute unmodified or modified versions of this source 63016Swollman * code provided that the above copyright notice and this and the 73016Swollman * following conditions are retained. 83016Swollman * 93016Swollman * This software is provided ``as is'', and comes with no warranties 103016Swollman * of any kind. I shall in no event be liable for anything that happens 113016Swollman * to anyone/anything when using this software. 123016Swollman */ 133016Swollman 1492986Sobrien#include <sys/cdefs.h> 1592986Sobrien__FBSDID("$FreeBSD$"); 1692986Sobrien 173016Swollman#include "rand48.h" 183016Swollman 193016Swollmanunsigned short _rand48_seed[3] = { 203016Swollman RAND48_SEED_0, 213016Swollman RAND48_SEED_1, 223016Swollman RAND48_SEED_2 233016Swollman}; 243016Swollmanunsigned short _rand48_mult[3] = { 253016Swollman RAND48_MULT_0, 263016Swollman RAND48_MULT_1, 273016Swollman RAND48_MULT_2 283016Swollman}; 293016Swollmanunsigned short _rand48_add = RAND48_ADD; 303016Swollman 313016Swollmanvoid 323016Swollman_dorand48(unsigned short xseed[3]) 333016Swollman{ 343016Swollman unsigned long accu; 353016Swollman unsigned short temp[2]; 363016Swollman 373016Swollman accu = (unsigned long) _rand48_mult[0] * (unsigned long) xseed[0] + 383016Swollman (unsigned long) _rand48_add; 393016Swollman temp[0] = (unsigned short) accu; /* lower 16 bits */ 403016Swollman accu >>= sizeof(unsigned short) * 8; 413016Swollman accu += (unsigned long) _rand48_mult[0] * (unsigned long) xseed[1] + 423016Swollman (unsigned long) _rand48_mult[1] * (unsigned long) xseed[0]; 433016Swollman temp[1] = (unsigned short) accu; /* middle 16 bits */ 443016Swollman accu >>= sizeof(unsigned short) * 8; 453016Swollman accu += _rand48_mult[0] * xseed[2] + _rand48_mult[1] * xseed[1] + _rand48_mult[2] * xseed[0]; 463016Swollman xseed[0] = temp[0]; 473016Swollman xseed[1] = temp[1]; 483016Swollman xseed[2] = (unsigned short) accu; 493016Swollman} 50