NFFT  3.3.0
rand.c
1 /*
2  * Copyright (c) 2002, 2015 Jens Keiner, Stefan Kunis, Daniel Potts
3  *
4  * This program is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU General Public License as published by the Free Software
6  * Foundation; either version 2 of the License, or (at your option) any later
7  * version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12  * details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc., 51
16  * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 /* $Id: util.c 3483 2010-04-23 19:02:34Z keiner $ */
20 
21 #include "infft.h"
22 
23 R Y(drand48)(void)
24 {
25 #ifdef HAVE_DRAND48
26  return (R)(drand48());
27 #else
28  return ((R)rand())/((R)RAND_MAX);
29 #endif
30 }
31 
32 void Y(srand48)(long int seed)
33 {
34 #ifdef HAVE_SRAND48
35  srand48(seed);
36 #else
37  srand((unsigned int)seed);
38 #endif
39 }
40 
41 void Y(vrand_unit_complex)(C *x, const INT n)
42 {
43  INT k;
44 
45  for (k = 0; k < n; k++)
46  x[k] = Y(drand48)() + II * Y(drand48)();
47 }
48 
49 void Y(vrand_shifted_unit_double)(R *x, const INT n)
50 {
51  INT k;
52 
53  for (k = 0; k < n; k++)
54  x[k] = Y(drand48)() - K(0.5);
55 }
56 
57 void Y(vrand_real)(R *x, const INT n, const R a, const R b)
58 {
59  INT k;
60 
61  for (k = 0; k < n; k++)
62  x[k] = a + Y(drand48)() * (b - a);
63 }