133965Sjdp/* $OpenBSD: drand48.c,v 1.7 2015/09/14 13:30:17 guenther Exp $ */ 289857Sobrien/* 360484Sobrien * Copyright (c) 1993 Martin Birgmeier 433965Sjdp * All rights reserved. 533965Sjdp * 633965Sjdp * You may redistribute unmodified or modified versions of this source 733965Sjdp * code provided that the above copyright notice and this and the 833965Sjdp * following conditions are retained. 933965Sjdp * 1033965Sjdp * This software is provided ``as is'', and comes with no warranties 1133965Sjdp * of any kind. I shall in no event be liable for anything that happens 1233965Sjdp * to anyone/anything when using this software. 1333965Sjdp */ 1433965Sjdp 1533965Sjdp#include <math.h> 1633965Sjdp#include "rand48.h" 1733965Sjdp 1860484Sobriendouble 1960484Sobriendrand48(void) 2060484Sobrien{ 2133965Sjdp if (__rand48_deterministic == 0) { 2289857Sobrien unsigned short rseed[3]; 2389857Sobrien 2489857Sobrien arc4random_buf(rseed, sizeof rseed); 2589857Sobrien return ldexp((double) rseed[0], -48) + 2633965Sjdp ldexp((double) rseed[1], -32) + 2733965Sjdp ldexp((double) rseed[2], -16); 2833965Sjdp } 2933965Sjdp return erand48(__rand48_seed); 3033965Sjdp} 3189857Sobrien