3 void RandomSelection_Init()
5 RandomSelection_totalweight = 0;
6 RandomSelection_chosen_ent = NULL;
7 RandomSelection_chosen_float = 0;
8 RandomSelection_chosen_string = string_null;
9 RandomSelection_best_priority = -1;
12 void RandomSelection_Add(entity e, float f, string s, float weight, float priority)
14 if (priority > RandomSelection_best_priority)
16 RandomSelection_best_priority = priority;
17 RandomSelection_chosen_ent = e;
18 RandomSelection_chosen_float = f;
19 RandomSelection_chosen_string = s;
20 RandomSelection_totalweight = weight;
22 else if (priority == RandomSelection_best_priority)
24 RandomSelection_totalweight += weight;
25 if (random() * RandomSelection_totalweight <= weight)
27 RandomSelection_chosen_ent = e;
28 RandomSelection_chosen_float = f;
29 RandomSelection_chosen_string = s;
35 // prandom - PREDICTABLE random number generator (not seeded yet)
42 c = crc16(false, strcat(ftos(prandom_seed), ftos(prandom_seed + M_PI)));
45 #ifdef USE_PRANDOM_DEBUG
46 LOG_TRACE("RANDOM -> ", ftos(c), "\n");
49 return c / 65536; // in [0..1[
67 void psrandom(float seed)
70 #ifdef USE_PRANDOM_DEBUG
71 LOG_TRACE("SRANDOM ", ftos(seed), "\n");
75 #ifdef USE_PRANDOM_DEBUG
78 LOG_TRACE("Current random seed = ", ftos(prandom_seed), "\n");