_rand48.c revision 3016
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 143016Swollman#include "rand48.h" 153016Swollman 163016Swollmanunsigned short _rand48_seed[3] = { 173016Swollman RAND48_SEED_0, 183016Swollman RAND48_SEED_1, 193016Swollman RAND48_SEED_2 203016Swollman}; 213016Swollmanunsigned short _rand48_mult[3] = { 223016Swollman RAND48_MULT_0, 233016Swollman RAND48_MULT_1, 243016Swollman RAND48_MULT_2 253016Swollman}; 263016Swollmanunsigned short _rand48_add = RAND48_ADD; 273016Swollman 283016Swollmanvoid 293016Swollman_dorand48(unsigned short xseed[3]) 303016Swollman{ 313016Swollman unsigned long accu; 323016Swollman unsigned short temp[2]; 333016Swollman 343016Swollman accu = (unsigned long) _rand48_mult[0] * (unsigned long) xseed[0] + 353016Swollman (unsigned long) _rand48_add; 363016Swollman temp[0] = (unsigned short) accu; /* lower 16 bits */ 373016Swollman accu >>= sizeof(unsigned short) * 8; 383016Swollman accu += (unsigned long) _rand48_mult[0] * (unsigned long) xseed[1] + 393016Swollman (unsigned long) _rand48_mult[1] * (unsigned long) xseed[0]; 403016Swollman temp[1] = (unsigned short) accu; /* middle 16 bits */ 413016Swollman accu >>= sizeof(unsigned short) * 8; 423016Swollman accu += _rand48_mult[0] * xseed[2] + _rand48_mult[1] * xseed[1] + _rand48_mult[2] * xseed[0]; 433016Swollman xseed[0] = temp[0]; 443016Swollman xseed[1] = temp[1]; 453016Swollman xseed[2] = (unsigned short) accu; 463016Swollman} 47