]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/prandom.qc
Merge branch 'samual/water_and_damage_blur' into samual/hud_contents
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / prandom.qc
1 // prandom - PREDICTABLE random number generator (not seeded yet)
2
3 #ifdef USE_PRANDOM
4 float prandom_seed;
5 float prandom()
6 {
7         float c;
8         c = crc16(FALSE, strcat(ftos(prandom_seed), ftos(prandom_seed + M_PI)));
9         prandom_seed = c;
10
11 #ifdef USE_PRANDOM_DEBUG
12         dprint("RANDOM -> ", ftos(c), "\n");
13 #endif
14
15         return c / 65536; // in [0..1[
16 }
17
18 vector prandomvec()
19 {
20         vector v;
21
22         do
23         {
24                 v_x = prandom();
25                 v_y = prandom();
26                 v_z = prandom();
27         }
28         while(v * v > 1);
29
30         return v;
31 }
32
33 void psrandom(float seed)
34 {
35         prandom_seed = seed;
36 #ifdef USE_PRANDOM_DEBUG
37         dprint("SRANDOM ", ftos(seed), "\n");
38 #endif
39 }
40
41 #ifdef USE_PRANDOM_DEBUG
42 void prandom_debug()
43 {
44         dprint("Current random seed = ", ftos(prandom_seed), "\n");
45 }
46 #endif
47 #endif