source: git/kernel/misc.cc @ 762407

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