source: cpp/frams/util/rndutil.cpp @ 121

Last change on this file since 121 was 121, checked in by sz, 10 years ago

updated file headers and makefiles

  • Property svn:eol-style set to native
File size: 1.3 KB
Line 
1// This file is a part of the Framsticks GDK.
2// Copyright (C) 2002-2014  Maciej Komosinski and Szymon Ulatowski.  See LICENSE.txt for details.
3// Refer to http://www.framsticks.com/ for further information.
4
5#include "rndutil.h"
6#include <common/nonstd_math.h>
7#include <stdlib.h>
8
9unsigned short pseudornd(short x)
10{
11static long seed=0;
12long y;
13if (x<=0) {seed=-x; return 0;}
14seed=(y=(3677*seed+3680)&0x7fffffff)-1;
15return (unsigned short)(((unsigned short)y)%(x));//rzutowanie y->unsigned short to pewnie blad bo zmniejsza wartosc ktorej sie potem robi modulo, ale pseudornd sluzy chyba tylko do generowania randomowych world map? i modulo i tak jest tam bardzo male, lepiej niczego nie zmieniac bo po co maja pliki z ustawieniami zmienic swoje przypadkowe znaczenie
16}
17
18double CustomRnd(double *tab)
19{
20double *range=tab+1+2*randomN((int)(0.5+tab[0]));
21return range[0]+rnd0N(range[1]-range[0]);
22}
23
24double RandomGener::Uni(double begin, double end)
25{
26return begin+rnd01*(end-begin);
27}
28
29double RandomGener::GaussStd()
30{
31if (isNextGauss) {isNextGauss=0; return nextGauss;}
32double v1,v2,s;
33do {
34v1=2*rnd01-1; //-1..1
35v2=2*rnd01-1; //-1..1
36s=v1*v1+v2*v2;
37} while (s>=1);
38double mult=sqrt(-2*log(s)/s);
39nextGauss=v2*mult;
40isNextGauss=1;
41return v1*mult;
42}
43
44double RandomGener::Gauss(double m,double s)
45{return m+s*GaussStd();}
46
47RandomGener RndGen;
Note: See TracBrowser for help on using the repository browser.