~chaffra/+junk/trilinos

« back to all changes in this revision

Viewing changes to packages/sacado/test/utils/Sacado_Random.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Prud'homme, Christophe Prud'homme, Johannes Ring
  • Date: 2009-12-13 12:53:22 UTC
  • mfrom: (5.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20091213125322-in0nrdjc55deqsw9
Tags: 10.0.3.dfsg-1
[Christophe Prud'homme]
* New upstream release

[Johannes Ring]
* debian/patches/libname.patch: Add prefix 'libtrilinos_' to all
  libraries. 
* debian/patches/soname.patch: Add soversion to libraries.
* debian/watch: Update download URL.
* debian/control:
  - Remove python-numeric from Build-Depends (virtual package).
  - Remove automake and autotools from Build-Depends and add cmake to
    reflect switch to CMake.
  - Add python-support to Build-Depends.
* debian/rules: 
  - Cleanup and updates for switch to CMake.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// $Id: Sacado_Random.cpp,v 1.7 2008/06/06 15:50:05 jmwille Exp $ 
2
 
// $Source: /space/CVS/Trilinos/packages/sacado/test/utils/Sacado_Random.cpp,v $ 
3
 
// @HEADER
4
 
// ***********************************************************************
5
 
// 
6
 
//                           Sacado Package
7
 
//                 Copyright (2006) Sandia Corporation
8
 
// 
9
 
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
10
 
// the U.S. Government retains certain rights in this software.
11
 
// 
12
 
// This library is free software; you can redistribute it and/or modify
13
 
// it under the terms of the GNU Lesser General Public License as
14
 
// published by the Free Software Foundation; either version 2.1 of the
15
 
// License, or (at your option) any later version.
16
 
//  
17
 
// This library is distributed in the hope that it will be useful, but
18
 
// WITHOUT ANY WARRANTY; without even the implied warranty of
19
 
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20
 
// Lesser General Public License for more details.
21
 
//  
22
 
// You should have received a copy of the GNU Lesser General Public
23
 
// License along with this library; if not, write to the Free Software
24
 
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25
 
// USA
26
 
// Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
27
 
// (etphipp@sandia.gov).
28
 
// 
29
 
// ***********************************************************************
30
 
// @HEADER
31
 
 
32
 
#include <cmath>
33
 
#include <iostream>
34
 
#include <cstdlib>
35
 
 
36
 
#include "Sacado_Random.hpp"
37
 
 
38
 
Sacado::Random::Random(double a_, double b_) :
39
 
  a(a_),
40
 
  b(b_),
41
 
  seed(static_cast<double>(rand()))
42
 
{
43
 
  // rand() can return 0 or 2147483647, so adjust seed if that happens
44
 
  if ((seed == 0.0) || (seed == 2147483647.0))
45
 
    seed = 1.0;
46
 
}
47
 
 
48
 
Sacado::Random::Random(double a_, double b_, int s) :
49
 
  a(a_),
50
 
  b(b_),
51
 
  seed(0.0)
52
 
{
53
 
  setSeed(s);
54
 
}
55
 
 
56
 
Sacado::Random::~Random()
57
 
{
58
 
}
59
 
 
60
 
void
61
 
Sacado::Random::setSeed(int s) {
62
 
  int ss = checkSeed("setSeed", s);
63
 
  srand(ss);
64
 
  seed = static_cast<double>(s);
65
 
}
66
 
 
67
 
double
68
 
Sacado::Random::number() {
69
 
  const double A = 16807.0;
70
 
  const double bigInt = 2147483647.0;
71
 
      
72
 
  seed = std::fmod(A*seed, bigInt);
73
 
  return (b-a)*(seed/bigInt) + a;
74
 
}
75
 
 
76
 
int
77
 
Sacado::Random::checkSeed(const std::string& func, int s) {
78
 
  if ((s < 1) || (s > 2147483646)) {
79
 
    std::cerr << "Error in Sacado::Random::" << s << "():  " 
80
 
              << "supplied seed " 
81
 
              << s << " is not an integer between 1 and 2147483646." 
82
 
              << std::endl << "Using a seed of 1 instead." << std::endl;
83
 
    return 1;
84
 
  }
85
 
  else
86
 
    return s;
87
 
}