AnimatLab  2
Test
gpu_random.h
1 /*
2  Copyright (c) 2007 A. Arnold and J. A. van Meel, FOM institute
3  AMOLF, Amsterdam; all rights reserved unless otherwise stated.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  In addition to the regulations of the GNU General Public License,
11  publications and communications based in parts on this program or on
12  parts of this program are required to cite the article
13  "Harvesting graphics power for MD simulations"
14  by J.A. van Meel, A. Arnold, D. Frenkel, S. F. Portegies Zwart and
15  R. G. Belleman, arXiv:0709.3225.
16 
17  This program 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  General Public License for more details.
21 
22  You should have received a copy of the GNU General Public License
23  along with this program; if not, write to the Free Software
24  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25  MA 02111-1307 USA
26 */
27 #ifndef _RANDOM_H_
28 #define _RANDOM_H_
29 
42 class RNG_rand48 {
43  int stride;
44 
46  void *state;
48  void *res;
49 
51  int threadsX;
53  int blocksX;
54 
57  unsigned int A0, A1, C0, C1;
58 
60  static const unsigned long long a = 0x5DEECE66DLL, c = 0xB;
61 
63  void init(int seed);
65  void cleanup();
66 
67  // maximum value of random number
68  int rand_max;
69 
70 public:
71  static const unsigned int MAX_RANGE=0x7FFFFFFF;
72 
74  RNG_rand48(int seed, int _max=0): res(0), rand_max(_max) { init(seed); }
76  ~RNG_rand48() { cleanup(); }
77 
79  void generate(int n);
80 
82  void generate(int n, int n_max);
83 
87  void get(int *r, int n);
88 
91  void *get_random_numbers() { return res; }
92 
93 private:
94  void generate_int(int n, int n_max, int offset);
95 
96 };
97 
98 #endif
void generate(int n)
RNG_rand48(int seed, int _max=0)
initialize the RNG with seed, just as the standard srand48-function
Definition: gpu_random.h:74
void * get_random_numbers()
Definition: gpu_random.h:91