source: git/kernel/misc.cc @ fbc7cb

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