source: git/kernel/misc.cc @ a5b80a

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