source: git/kernel/misc.cc @ 8de3388

spielwiese
Last change on this file since 8de3388 was 8de3388, checked in by Andreas Steenpaß <steenpas@…>, 14 years ago
M kernel/misc.cc M Singular/misc_ip.cc automatically closes all links on exit git-svn-id: file:///usr/local/Singular/svn/trunk@13019 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 2.3 KB
RevLine 
[35aab3]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 "mod2.h"
16#include <mylimits.h>
17#include "omalloc.h"
18#include "structs.h"
[690e21e]19#include "options.h"
[35aab3]20#include "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
28#define SI_DONT_HAVE_GLOBAL_VARS
29
30//#ifdef HAVE_LIBPARSER
31//#  include "libparse.h"
32//#endif /* HAVE_LIBPARSER */
33
34#ifdef HAVE_FACTORY
35#include <factory.h>
[d3e630]36/* libfac version strings */
[35aab3]37  extern const char * libfac_version;
38  extern const char * libfac_date;
39#endif
[d3e630]40
[c1526f]41#include <si_gmp.h>
[35aab3]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#ifdef buildin_rand
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
[63105e5]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                  */
[35aab3]94
95
[ac8f221]96int siSeed = 1;
[35aab3]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#endif
109
Note: See TracBrowser for help on using the repository browser.