source: git/kernel/misc.cc @ cdec33

spielwiese
Last change on this file since cdec33 was 24fd70, checked in by Hans Schoenemann <hannes@…>, 13 years ago
SI_DONT_HAVE_GLOBAL_VARS git-svn-id: file:///usr/local/Singular/svn/trunk@13634 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • 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 <kernel/options.h>
20#include <kernel/febase.h>
21//#include "cntrlc.h"
22#include <kernel/kstd1.h>
23#include <kernel/timer.h>
24#include <kernel/intvec.h>
25#include <kernel/ring.h>
26#include <kernel/p_Procs.h>
27
28//#ifdef HAVE_LIBPARSER
29//#  include "libparse.h"
30//#endif /* HAVE_LIBPARSER */
31
32#ifdef HAVE_FACTORY
33#define SI_DONT_HAVE_GLOBAL_VARS
34#  include <factory/factory.h>
35/* libfac version strings */
36  extern const char * libfac_version;
37  extern const char * libfac_date;
38#endif
39
40#include <si_gmp.h>
41#ifdef HAVE_MPSR
42#include <MP_Config.h>
43#endif
44
45/* init bins from structs.h */
46
47omBin char_ptr_bin = omGetSpecBin(sizeof(char_ptr));
48
49/*0 implementation*/
50
51/*2
52* the renice routine for very large jobs
53* works only on unix machines,
54* testet on : linux, HP 9.0
55*
56*#include <sys/times.h>
57*#include <sys/resource.h>
58*extern "C" int setpriority(int,int,int);
59*void very_nice()
60*{
61*#ifndef NO_SETPRIORITY
62*  setpriority(PRIO_PROCESS,0,19);
63*#endif
64*  sleep(10);
65*}
66*/
67
68/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
69/*
70 *
71 *  A prime modulus multiplicative linear congruential
72 *  generator (PMMLCG), or "Lehmer generator".
73 *  Implementation directly derived from the article:
74 *
75 *        S. K. Park and K. W. Miller
76 *        Random Number Generators: Good Ones are Hard to Find
77 *        CACM vol 31, #10. Oct. 1988. pp 1192-1201.
78 *
79 *  Using the following multiplier and modulus, we obtain a
80 *  generator which:
81 *
82 *        1)  Has a full period: 1 to 2^31 - 2.
83 *        2)  Is testably "random" (see the article).
84 *        3)  Has a known implementation by E. L. Schrage.
85 */
86
87
88#define  A        16807        /*  A "good" multiplier          */
89#define  M   2147483647        /*  Modulus: 2^31 - 1          */
90#define  Q       127773        /*  M / A                  */
91#define  R         2836        /*  M % A                  */
92
93
94int siSeed = 1;
95
96
97int siRand()
98{
99  siSeed = A * (siSeed % Q) - R * (siSeed / Q);
100
101  if ( siSeed < 0 )
102    siSeed += M;
103
104  return( siSeed );
105}
106
Note: See TracBrowser for help on using the repository browser.