original 1.0.1 release
[xwelltris.git] / src / rndgen.cxx
blob310f483efac6bf2ad0f98b995462b3300f62bdf0
1 // docm_prefix(///)
2 /****************************************************************************
3 * Copyright (C) 2002 by Leo Khramov
4 * email: leo@xnc.dubna.su
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 ****************************************************************************/
16 // $Id: rndgen.cxx,v 1.1.1.1 2003/01/04 11:37:22 leo Exp $
18 /// module description
19 /// Dr. Park's algorithm published in the Oct. '88 ACM
20 /// "Random Number Generators: Good Ones Are Hard To Find"
21 /// His version available at ftp://cs.wm.edu/pub/rngs.tar
22 /// Present form by many authors.
25 static int Seed = 1; /* This is required to be 32 bits long */
27 //===========================================================================
28 /// global SetRNG(long)
29 /// Set random seed generator,
30 /// Given an integer, this routine initializes the RNG seed.
31 /// tags random_gen
32 void SetRNG(long s)
34 Seed = (int) s;
37 //===========================================================================
38 /// global LongRNG()
39 /// Returns an pseudo random integer between 0 and 2147483647, inclusive.
40 /// tags random_gen
41 long LongRNG()
43 if ((Seed = Seed % 44488 * 48271 - Seed / 44488 * 3399) < 0)
44 Seed += 2147483647;
45 return (long) (Seed - 1);