dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #01668
srand et. al.
Kernel/math is calling methods srand48 and drand48 which are not available
under Windows. I did a search for a possible Windows replacement and found
this reference: (didn't look for the source yet though)
1 CLHEP/Random/DRand48Engine.h
// $Id: DRand48Engine.h,v 1.12 2000/04/17 22:59:31 mf Exp $
// -*- C++ -*-
//
// -----------------------------------------------------------------------
// HEP Random
// --- DRand48Engine ---
// class header file
// -----------------------------------------------------------------------
// This file is part of Geant4 (simulation toolkit for HEP).
//
// Random engine using drand48() and srand48() functions from C standard
// library to implement the flat() basic distribution and for setting
// seeds.
// For Windows/NT platforms (WIN32), the code for drand48 has been
// extracted from the GNU C Library 2.0.1 and adapted for the native
// types.
// Copy constructor and operator= are private for objects of this class.
// =======================================================================
// G.Cosmo - Created: 5th September 1995
// - Minor corrections: 31st October 1996
// - Added methods for engine status: 19th November 1996
// - Added srand48(), seed48(), drand48() implementations
// for Windows/NT: 6th March 1997
// - setSeed(), setSeeds() now have default dummy argument
// set to zero: 11th July 1997
// E.Tcherniaev - Porting on KCC compiler: 2nd Feb 1998
// G.Cosmo - Private copy constructor and operator=: 26th Feb 1998
// J.Marraffino - Added stream operators and related constructor.
// Added automatic seed selection from seed table and
// engine counter: 16th Feb 1998
// =======================================================================
#ifndef DRand48Engine_h
#define DRand48Engine_h 1
#include "CLHEP/Random/RandomEngine.h"
#if defined(__KCC)
// Those function are available on all unix platform but their
// prototypes are not included in stdlib when KCC strict flag is
// set
extern "C" {
extern double drand48(void);
extern void srand48(long);
extern unsigned short * seed48(unsigned short int [3]);
}
#endif /* KCC */
#ifdef WIN32
// ********************************************************************
// Code extracted from GNU C Library 2.0.1
/* Data structure for communication with thread safe versions. */
struct drand48_data
{
unsigned short int X[3]; /* Current state. */
unsigned short int a[3]; /* Factor in congruential formula. */
unsigned short int c; /* Additive const. in congruential
formula. */
unsigned short int old_X[3]; /* Old state. */
int init; /* Flag for initializing.
*/
};
/* Internal function to compute next state of the generator. */
extern "C" { int drand48_iterate (unsigned short int xsubi[3],
struct drand48_data
*buffer); }
/* Return non-negative, double-precision floating-point value in
[0.0,1.0). */
extern "C" { int drand48_r (struct drand48_data *buffer, double *result);
}
extern "C" { int erand48_r (unsigned short int xsubi[3],
struct drand48_data *buffer,
double *result); }
/* Seed random number generator. */
extern "C" { int srand48_r (long seedval, struct drand48_data *buffer); }
extern "C" { int seed48_r (unsigned short int seed16v[3],
struct drand48_data *buffer); }
/* Return non-negative, double-precision floating-point value in
[0.0,1.0). */
extern "C" { double drand48 (void); }
extern "C" { double erand48 (unsigned short int xsubi[3]); }
/* Seed random number generator. */
extern "C" { void srand48 (long seedval); }
extern "C" { unsigned short int *seed48 (unsigned short int seed16v[3]);
}
// End Code extracted from GNU C Library 2.0.1
// ********************************************************************
#endif /* WIN32 */
class DRand48Engine : public HepRandomEngine {
public:
DRand48Engine(HepStd::istream& is);
DRand48Engine();
DRand48Engine(long seed);
DRand48Engine(HepInt rowIndex, HepInt colIndex);
virtual ~DRand48Engine();
// Constructors and destructor
HepDouble flat();
// It returns a pseudo random number between 0 and 1,
// according to the standard stdlib random function drand48()
// but excluding the end points.
void flatArray (const HepInt size, HepDouble* vect);
// Fills the array "vect" of specified size with flat random values.
void setSeed(long seed, HepInt dum=0);
// Sets the state of the algorithm according to seed.
void setSeeds(const long * seeds, HepInt dum=0);
// Sets the state of the algorithm according to the zero terminated
// array of seeds. Only the first seed is used.
void saveStatus( const char filename[] = "DRand48.conf" ) const;
// Saves on file DRand48.conf the current engine status.
void restoreStatus( const char filename[] = "DRand48.conf" );
// Reads from file DRand48.conf the last saved engine status
// and restores it.
void showStatus() const;
// Dumps the engine status on the screen.
friend HepStd::ostream& operator<< (HepStd::ostream& os, const
DRand48Engine& e);
friend HepStd::istream& operator>> (HepStd::istream& is,
DRand48Engine& e);
private:
static HepInt numEngines;
static HepInt maxIndex;
DRand48Engine(const DRand48Engine &p);
DRand48Engine & operator = (const DRand48Engine &p);
// Private copy constructor and assignment operator.
};
#endif
Follow ups