/* -*- mode:c++; coding: koi8-r -*- */

/* $Id: SeededEnthropy.cpp,v 1.1 2003/04/14 20:53:07 cher Exp $ */
/* Copyright (C) 2003 Alexander Chernov <cher@unicorn.cmc.msu.ru> */

/*
 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 2 of the License, or (at your option) any later version.

 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 Lesser General Public License for more details.

 See the `COPYING' file for the full terms and conditions.
*/

#include "SeededEnthropy.hpp"

#include "../double/cephes.h"

SeededEnthropy::SeededEnthropy(ByteSource *bsrc)
  throw (BadArgsError,ReadError)
  : ExternalEnthropy(bsrc)
{
  unsigned short s1, s2, s3;
  unsigned long long v = 0ULL;

  this->src->read(45, (void*) &v, 0);
  s1 = v & 0x7fffull;
  v >>= 15ull;
  s2 = v & 0x7fffull;
  v >>= 15ull;
  s3 = v & 0x7fffull;
  cephes_srand(s1, s2, s3);
}

double
SeededEnthropy::getDouble()
  throw ()
{
  return cephes_drand() - 1.0;
}

/*
 * Local variables:
 *  compile-command: "make -C .."
 *  c++-font-lock-extra-types: ("[A-Z]\\sw*[a-z]\\sw*")
 * End:
 */
