random.cc (3918:1f9a98d198e8) | random.cc (4045:43eb54e807d1) |
---|---|
1/* 2 * Copyright (c) 2003-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 26 unchanged lines hidden (view full) --- 35#ifdef __SUNPRO_CC 36#include <stdlib.h> 37#include <math.h> 38#endif 39 40#include <cstdlib> 41#include <cmath> 42 | 1/* 2 * Copyright (c) 2003-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 26 unchanged lines hidden (view full) --- 35#ifdef __SUNPRO_CC 36#include <stdlib.h> 37#include <math.h> 38#endif 39 40#include <cstdlib> 41#include <cmath> 42 |
43 44#include "sim/param.hh" | |
45#include "base/random.hh" | 43#include "base/random.hh" |
46#include "base/trace.hh" | |
47 48using namespace std; 49 | 44 45using namespace std; 46 |
50class RandomContext : public ParamContext | 47uint32_t 48getInt32() |
51{ | 49{ |
52 public: 53 RandomContext(const string &_iniSection) 54 : ::ParamContext(_iniSection) {} 55 ~RandomContext() {} 56 57 void checkParams(); 58}; 59 60RandomContext paramContext("random"); 61 62Param<unsigned> 63seed(¶mContext, "seed", "seed to random number generator", 1); 64 65void 66RandomContext::checkParams() 67{ 68 ::srand48(seed); | 50 return mrand48() & 0xffffffff; |
69} 70 | 51} 52 |
71long 72getLong() | 53double 54getDouble() |
73{ | 55{ |
74 return mrand48(); | 56 return drand48(); |
75} 76 77double 78m5round(double r) 79{ 80#if defined(__sun) 81 double val; 82 fp_rnd oldrnd = fpsetround(FP_RN); --- 17 unchanged lines hidden (view full) --- 100uint64_t 101getUniformPos(uint64_t min, uint64_t max) 102{ 103 double r; 104 r = drand48() * (max-min) + min; 105 106 return (uint64_t)m5round(r); 107} | 57} 58 59double 60m5round(double r) 61{ 62#if defined(__sun) 63 double val; 64 fp_rnd oldrnd = fpsetround(FP_RN); --- 17 unchanged lines hidden (view full) --- 82uint64_t 83getUniformPos(uint64_t min, uint64_t max) 84{ 85 double r; 86 r = drand48() * (max-min) + min; 87 88 return (uint64_t)m5round(r); 89} |
108 109 110// idea for generating a double from erand48 111double 112getDouble() 113{ 114 union { 115 uint32_t _long[2]; 116 uint16_t _short[4]; 117 }; 118 119 _long[0] = mrand48(); 120 _long[1] = mrand48(); 121 122 return ldexp((double) _short[0], -48) + 123 ldexp((double) _short[1], -32) + 124 ldexp((double) _short[2], -16); 125} | |