Last change
on this file since 152 was
121,
checked in by sz, 11 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 | |
---|
9 | unsigned short pseudornd(short x) |
---|
10 | { |
---|
11 | static long seed=0; |
---|
12 | long y; |
---|
13 | if (x<=0) {seed=-x; return 0;} |
---|
14 | seed=(y=(3677*seed+3680)&0x7fffffff)-1; |
---|
15 | return (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 | |
---|
18 | double CustomRnd(double *tab) |
---|
19 | { |
---|
20 | double *range=tab+1+2*randomN((int)(0.5+tab[0])); |
---|
21 | return range[0]+rnd0N(range[1]-range[0]); |
---|
22 | } |
---|
23 | |
---|
24 | double RandomGener::Uni(double begin, double end) |
---|
25 | { |
---|
26 | return begin+rnd01*(end-begin); |
---|
27 | } |
---|
28 | |
---|
29 | double RandomGener::GaussStd() |
---|
30 | { |
---|
31 | if (isNextGauss) {isNextGauss=0; return nextGauss;} |
---|
32 | double v1,v2,s; |
---|
33 | do { |
---|
34 | v1=2*rnd01-1; //-1..1 |
---|
35 | v2=2*rnd01-1; //-1..1 |
---|
36 | s=v1*v1+v2*v2; |
---|
37 | } while (s>=1); |
---|
38 | double mult=sqrt(-2*log(s)/s); |
---|
39 | nextGauss=v2*mult; |
---|
40 | isNextGauss=1; |
---|
41 | return v1*mult; |
---|
42 | } |
---|
43 | |
---|
44 | double RandomGener::Gauss(double m,double s) |
---|
45 | {return m+s*GaussStd();} |
---|
46 | |
---|
47 | RandomGener RndGen; |
---|
Note: See
TracBrowser
for help on using the repository browser.