diff options
Diffstat (limited to 'src/mt/qran.h')
| -rw-r--r-- | src/mt/qran.h | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/mt/qran.h b/src/mt/qran.h new file mode 100644 index 0000000..10f9a6f --- /dev/null +++ b/src/mt/qran.h | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | /************************************************************************* | ||
| 2 | * | ||
| 3 | * HTCd - Copyright (C) 1998-2006 Henrik Rydberg | ||
| 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 | * This program is distributed in the hope that it will be useful, | ||
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | * GNU General Public License for more details. | ||
| 14 | * | ||
| 15 | * You should have received a copy of the GNU General Public License | ||
| 16 | * along with this program; if not, write to the Free Software | ||
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 18 | */ | ||
| 19 | |||
| 20 | #ifndef QRANH | ||
| 21 | #define QRANH | ||
| 22 | |||
| 23 | #include <math.h> | ||
| 24 | |||
| 25 | inline double QUniform(unsigned long& q) { | ||
| 26 | q=1664525L*q+1013904223L; | ||
| 27 | unsigned long long s=q;s<<=20;s|=(1023ULL<<52);return *(double*)&s-1; | ||
| 28 | } | ||
| 29 | inline int QRanBit(unsigned long& q) { | ||
| 30 | if(q&131072U) { q=((q^19U)<<1)|1U; return 1; } | ||
| 31 | else { q<<=1; return 0; } | ||
| 32 | } | ||
| 33 | |||
| 34 | #endif | ||
