2 * This file is part of TISEAN
4 * Copyright (c) 1998-2007 Rainer Hegger, Holger Kantz, Thomas Schreiber
6 * TISEAN is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * TISEAN is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with TISEAN; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 /*Author: Rainer Hegger Last modified: Feb 11, 2006 */
22 Feb 11, 2006: First version
25 Creates a sequence of random numbers with arbitrary distribution
26 Input Paramters: x=original data defining the distribution
28 nc= number of random numbers to create
29 nb= number of bins for the distribution
30 iseed = seed for the random number generator
31 Return: rand = array containing the nc random numbers
46 extern void rescale_data(double*,unsigned long,double*,double*);
47 extern void check_alloc(void*);
48 extern unsigned long rnd_long(void);
49 extern void rnd_init(unsigned long);
51 double *rand_arb_dist(double *x,unsigned long nx,unsigned long nc,
52 unsigned int nb,unsigned long iseed)
54 double h,min,inter,*randarb,drnd,epsinv=1.0/(double)nb;
55 unsigned long i,j,*box,hrnd,nall=nx+nb;
57 rescale_data(x,nx,&min,&inter);
59 check_alloc(box=(unsigned long*)malloc(sizeof(unsigned long)*nb));
67 j=(unsigned int)(h*nb);
73 check_alloc(randarb=(double*)malloc(sizeof(double)*nc));
76 iseed=(unsigned long)time((time_t*)&iseed);
87 drnd=(double)rnd_long()/(double)ULONG_MAX*epsinv;
88 randarb[i]=min+((double)j*epsinv+drnd)*inter;