5 * - linear and additive congruential random number generators
6 * (see R. Sedgewick, Algorithms, Chapter 35)
8 * Implementation: R. Fuchs, EMBL Data Library, 1991
17 /* linear congruential method
19 * linrand() returns an unsigned long random number in the range 0 to r-1
24 static unsigned long mult(unsigned long p, unsigned long q)
26 unsigned long p1,p0,q1,q0;
28 p1 = p/m1; p0 = p % m1;
29 q1 = q/m1; q0 = q % m1;
30 return (unsigned long)((((p0*q1 + p1*q0) % m1) * m1 + p0*q0) % m);
34 /* additive congruential method
36 * addrand() returns an unsigned long random number in the range 0 to r-1
37 * The random number generator is initialized by addrandinit()
40 static unsigned long j;
41 static unsigned long a[55];
43 unsigned long addrand(unsigned long r)
46 /* fprintf(stdout,"\n j = %d",j); */
48 /* fprintf(stdout,"\n j = %d",j); */
51 a[j] = (a[x] + a[y]) % m;
52 /* a[j] = (a[(j+23)%55] + a[(j+54)%55]) % m; */
53 /* fprintf(stdout,"\n a[j] = %d",a[j]); */
54 return( ((a[j] / m1) * r) / m1 );
57 void addrandinit(unsigned long s)
63 a[j] = (mult(31,a[j-1]) + 1) % m;
66 /*********************************COPYRIGHT NOTICE**********************************/
67 /*© Centro de Regulacio Genomica */
70 /*Tue Oct 27 10:12:26 WEST 2009. */
71 /*All rights reserved.*/
72 /*This file is part of T-COFFEE.*/
74 /* T-COFFEE is free software; you can redistribute it and/or modify*/
75 /* it under the terms of the GNU General Public License as published by*/
76 /* the Free Software Foundation; either version 2 of the License, or*/
77 /* (at your option) any later version.*/
79 /* T-COFFEE is distributed in the hope that it will be useful,*/
80 /* but WITHOUT ANY WARRANTY; without even the implied warranty of*/
81 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the*/
82 /* GNU General Public License for more details.*/
84 /* You should have received a copy of the GNU General Public License*/
85 /* along with Foobar; if not, write to the Free Software*/
86 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/
87 /*............................................... |*/
88 /* If you need some more information*/
89 /* cedric.notredame@europe.com*/
90 /*............................................... |*/
94 /*********************************COPYRIGHT NOTICE**********************************/