source: git/kernel/misc.cc @ cab375

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