source: git/kernel/misc.cc @ 0f401f

spielwiese
Last change on this file since 0f401f was 0f401f, checked in by Hans Schoenemann <hannes@…>, 13 years ago
fixed options.h, numbers.h, restored ideals.cc
  • Property mode set to 100644
File size: 2.3 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 "intvec.h"
25#include "ring.h"
26#include "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 <si_gmp.h>
42#ifdef HAVE_MPSR
43#include <MP_Config.h>
44#endif
45
46/* init bins from structs.h */
47
48omBin char_ptr_bin = omGetSpecBin(sizeof(char_ptr));
49
50/*0 implementation*/
51
52/*2
53* the renice routine for very large jobs
54* works only on unix machines,
55* testet on : linux, HP 9.0
56*
57*#include <sys/times.h>
58*#include <sys/resource.h>
59*extern "C" int setpriority(int,int,int);
60*void very_nice()
61*{
62*#ifndef NO_SETPRIORITY
63*  setpriority(PRIO_PROCESS,0,19);
64*#endif
65*  sleep(10);
66*}
67*/
68
69/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
70/*
71 *
72 *  A prime modulus multiplicative linear congruential
73 *  generator (PMMLCG), or "Lehmer generator".
74 *  Implementation directly derived from the article:
75 *
76 *        S. K. Park and K. W. Miller
77 *        Random Number Generators: Good Ones are Hard to Find
78 *        CACM vol 31, #10. Oct. 1988. pp 1192-1201.
79 *
80 *  Using the following multiplier and modulus, we obtain a
81 *  generator which:
82 *
83 *        1)  Has a full period: 1 to 2^31 - 2.
84 *        2)  Is testably "random" (see the article).
85 *        3)  Has a known implementation by E. L. Schrage.
86 */
87
88
89#define  A        16807        /*  A "good" multiplier          */
90#define  M   2147483647        /*  Modulus: 2^31 - 1          */
91#define  Q       127773        /*  M / A                  */
92#define  R         2836        /*  M % A                  */
93
94
95int siSeed = 1;
96
97
98int siRand()
99{
100  siSeed = A * (siSeed % Q) - R * (siSeed / Q);
101
102  if ( siSeed < 0 )
103    siSeed += M;
104
105  return( siSeed );
106}
107
Note: See TracBrowser for help on using the repository browser.