source: git/kernel/misc.cc @ 5348866

spielwiese
Last change on this file since 5348866 was 5348866, checked in by Oleksandr Motsak <motsak@…>, 13 years ago
FIX: guarding all libfac_* variables with HAVE_LIBFAC
  • Property mode set to 100644
File size: 1.9 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/*
5* ABSTRACT:
6*/
7
8#include <kernel/mod2.h>
9
10#ifdef HAVE_FACTORY
11#define SI_DONT_HAVE_GLOBAL_VARS
12#  include <factory/factory.h>
13/* libfac version strings */
14#ifdef HAVE_LIBFAC
15  extern const char * libfac_version;
16  extern const char * libfac_date;
17#endif // #ifdef HAVE_LIBFAC
18#endif
19
20#include <coeffs/si_gmp.h>
21#include <omalloc/omalloc.h>
22
23#ifdef HAVE_MPSR
24#include <MP_Config.h>
25#endif
26
27/* init bins */
28
29omBin char_ptr_bin = omGetSpecBin(sizeof(char*));
30
31/*0 implementation*/
32
33/*2
34* the renice routine for very large jobs
35* works only on unix machines,
36* testet on : linux, HP 9.0
37*
38*#include <sys/times.h>
39*#include <sys/resource.h>
40*extern "C" int setpriority(int,int,int);
41*void very_nice()
42*{
43*#ifndef NO_SETPRIORITY
44*  setpriority(PRIO_PROCESS,0,19);
45*#endif
46*  sleep(10);
47*}
48*/
49
50/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
51/*
52 *
53 *  A prime modulus multiplicative linear congruential
54 *  generator (PMMLCG), or "Lehmer generator".
55 *  Implementation directly derived from the article:
56 *
57 *        S. K. Park and K. W. Miller
58 *        Random Number Generators: Good Ones are Hard to Find
59 *        CACM vol 31, #10. Oct. 1988. pp 1192-1201.
60 *
61 *  Using the following multiplier and modulus, we obtain a
62 *  generator which:
63 *
64 *        1)  Has a full period: 1 to 2^31 - 2.
65 *        2)  Is testably "random" (see the article).
66 *        3)  Has a known implementation by E. L. Schrage.
67 */
68
69
70#define  A        16807        /*  A "good" multiplier          */
71#define  M   2147483647        /*  Modulus: 2^31 - 1          */
72#define  Q       127773        /*  M / A                  */
73#define  R         2836        /*  M % A                  */
74
75
76int siSeed = 1;
77
78
79int siRand()
80{
81  siSeed = A * (siSeed % Q) - R * (siSeed / Q);
82
83  if ( siSeed < 0 )
84    siSeed += M;
85
86  return( siSeed );
87}
88
Note: See TracBrowser for help on using the repository browser.