source: git/kernel/misc.cc @ ba5e9e

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