Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
random.qh File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define crandom()
 Returns a random number between -1.0 and 1.0.
#define prandom_debug()
#define RandomSelection_AddEnt(e, weight, priority)
#define RandomSelection_AddFloat(f, weight, priority)
#define RandomSelection_AddString(s, weight, priority)
#define RandomSelection_AddVec(v, weight, priority)
#define USE_PRANDOM

Functions

ERASEABLE float DistributeEvenly_Get (float weight)
ERASEABLE float DistributeEvenly_GetRandomized (float weight)
ERASEABLE float DistributeEvenly_GetRounded (float weight)
ERASEABLE void DistributeEvenly_Init (float amount, float totalweight)
ERASEABLE float gsl_ran_ugaussian ()
 Returns a Gaussian random variate, with mean zero and standard deviation sigma 1 From the GNU Scientific Library.
float prandom ()
 Predictable random number generator (not seeded yet)
vector prandomvec ()
void psrandom (float seed)
ERASEABLE void RandomSelection_Add (entity e, float f, string s, vector v, float weight, float priority)
ERASEABLE void RandomSelection_Init ()

Variables

float RandomSelection_best_priority
entity RandomSelection_chosen_ent
float RandomSelection_chosen_float
string RandomSelection_chosen_string
vector RandomSelection_chosen_vec
float RandomSelection_totalweight

Macro Definition Documentation

◆ crandom

#define crandom ( )
Value:
(2 * (random() - 0.5))
float random(void)

Returns a random number between -1.0 and 1.0.

Definition at line 32 of file random.qh.

Referenced by ctf_Handle_Throw(), func_breakable_destroy(), havocbot_movetogoal(), Item_ScheduleRespawn(), ka_DropEvent(), LaunchDebris(), and tka_DropEvent().

◆ prandom_debug

#define prandom_debug ( )

Definition at line 44 of file random.qh.

Referenced by NET_HANDLE().

◆ RandomSelection_AddEnt

#define RandomSelection_AddEnt ( e,
weight,
priority )

◆ RandomSelection_AddFloat

#define RandomSelection_AddFloat ( f,
weight,
priority )
Value:
RandomSelection_Add(NULL, f, string_null, '0 0 0', weight, priority)
#define NULL
Definition post.qh:14

Definition at line 15 of file random.qh.

Referenced by NIX_ChooseNextWeapon(), RandomItems_GetRandomVanillaItemClassName(), and TeamBalance_FindBestTeam().

◆ RandomSelection_AddString

◆ RandomSelection_AddVec

#define RandomSelection_AddVec ( v,
weight,
priority )
Value:
RandomSelection_Add(NULL, 0, string_null, v, weight, priority)

Definition at line 17 of file random.qh.

◆ USE_PRANDOM

#define USE_PRANDOM

Definition at line 34 of file random.qh.

Function Documentation

◆ DistributeEvenly_Get()

ERASEABLE float DistributeEvenly_Get ( float weight)

Definition at line 52 of file random.qc.

53{
54 if (weight <= 0)
55 return 0;
59 return f;
60}
float DistributeEvenly_totalweight
Definition random.qc:39
float DistributeEvenly_amount
Definition random.qc:38

References DistributeEvenly_amount, and DistributeEvenly_totalweight.

Referenced by kh_LoserTeam(), and kh_WinnerTeam().

◆ DistributeEvenly_GetRandomized()

ERASEABLE float DistributeEvenly_GetRandomized ( float weight)

Definition at line 74 of file random.qc.

75{
76 if (weight <= 0)
77 return 0;
81 return f;
82}
float floor(float f)

References DistributeEvenly_amount, DistributeEvenly_totalweight, floor(), and random().

◆ DistributeEvenly_GetRounded()

ERASEABLE float DistributeEvenly_GetRounded ( float weight)

Definition at line 63 of file random.qc.

64{
65 if (weight <= 0)
66 return 0;
70 return f;
71}

References DistributeEvenly_amount, DistributeEvenly_totalweight, and floor().

◆ DistributeEvenly_Init()

ERASEABLE void DistributeEvenly_Init ( float amount,
float totalweight )

Definition at line 42 of file random.qc.

43{
45 LOG_TRACE("DistributeEvenly_Init: UNFINISHED DISTRIBUTION (", ftos(DistributeEvenly_amount),
46 " for ", ftos(DistributeEvenly_totalweight), " left!)");
47 DistributeEvenly_amount = (totalweight) ? amount : 0;
48 DistributeEvenly_totalweight = totalweight;
49}
#define LOG_TRACE(...)
Definition log.qh:76
string ftos(float f)

References DistributeEvenly_amount, DistributeEvenly_totalweight, ftos(), and LOG_TRACE.

Referenced by kh_LoserTeam(), and kh_WinnerTeam().

◆ gsl_ran_ugaussian()

ERASEABLE float gsl_ran_ugaussian ( )

Returns a Gaussian random variate, with mean zero and standard deviation sigma 1 From the GNU Scientific Library.

Definition at line 87 of file random.qc.

88{
89 static float lastvalue;
90 static bool lastvalue_set;
91 if (lastvalue_set)
92 {
93 lastvalue_set = false;
94 return lastvalue;
95 }
96
97 const float a = random() * (2 * M_PI);
98 const float b = sqrt(-2 * log(random()));
99 lastvalue = cos(a) * b;
100 lastvalue_set = true;
101 return sin(a) * b;
102}
float log(float f)
#define M_PI
Definition mathlib.qh:108
float cos(float f)
float sqrt(float f)
float sin(float f)

References cos(), log(), M_PI, random(), sin(), and sqrt().

Referenced by W_CalculateSpread().

◆ prandom()

float prandom ( )

Predictable random number generator (not seeded yet)

Definition at line 108 of file random.qc.

109 {
110 float c;
111 c = crc16(false, strcat(ftos(prandom_seed), ftos(prandom_seed + M_PI)));
112 prandom_seed = c;
113
114 #ifdef USE_PRANDOM_DEBUG
115 LOG_TRACE("RANDOM -> ", ftos(c));
116 #endif
117
118 return c / 65536; // in [0..1[
119 }
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
float prandom_seed
Definition random.qc:106

References ftos(), LOG_TRACE, M_PI, prandom_seed, and strcat().

Referenced by NET_HANDLE(), NET_HANDLE(), prandomvec(), SND_BRASS_RANDOM(), SND_CASINGS_RANDOM(), SND_GIB_SPLAT_RANDOM(), TossGib(), and turret_gibtoss().

◆ prandomvec()

vector prandomvec ( )

Definition at line 121 of file random.qc.

122 {
123 vector v;
124
125 do
126 {
127 v.x = prandom();
128 v.y = prandom();
129 v.z = prandom();
130 }
131 while (v * v > 1);
132
133 return v;
134 }
float prandom()
Predictable random number generator (not seeded yet)
Definition random.qc:108
vector
Definition self.qh:92

References prandom(), and vector.

Referenced by NET_HANDLE(), NET_HANDLE(), RaptorCBShellfragToss(), TossGib(), and turret_gibtoss().

◆ psrandom()

void psrandom ( float seed)

Definition at line 136 of file random.qc.

137 {
138 prandom_seed = seed;
139 #ifdef USE_PRANDOM_DEBUG
140 LOG_TRACE("SRANDOM ", ftos(seed));
141 #endif
142 }

References ftos(), LOG_TRACE, and prandom_seed.

Referenced by NET_HANDLE().

◆ RandomSelection_Add()

ERASEABLE void RandomSelection_Add ( entity e,
float f,
string s,
vector v,
float weight,
float priority )

Definition at line 14 of file random.qc.

15{
16 if (priority > RandomSelection_best_priority)
17 {
24 }
25 else if (priority == RandomSelection_best_priority)
26 {
28 if (random() * RandomSelection_totalweight <= weight)
29 {
34 }
35 }
36}
float RandomSelection_best_priority
Definition random.qh:4
float RandomSelection_chosen_float
Definition random.qh:6
string RandomSelection_chosen_string
Definition random.qh:7
float RandomSelection_totalweight
Definition random.qh:3
entity RandomSelection_chosen_ent
Definition random.qh:5
vector RandomSelection_chosen_vec
Definition random.qh:8

References entity(), random(), RandomSelection_best_priority, RandomSelection_chosen_ent, RandomSelection_chosen_float, RandomSelection_chosen_string, RandomSelection_chosen_vec, RandomSelection_totalweight, and vector.

Referenced by MUTATOR_HOOKFUNCTION().

◆ RandomSelection_Init()

Variable Documentation

◆ RandomSelection_best_priority

float RandomSelection_best_priority

Definition at line 4 of file random.qh.

Referenced by RandomSelection_Add(), and RandomSelection_Init().

◆ RandomSelection_chosen_ent

◆ RandomSelection_chosen_float

◆ RandomSelection_chosen_string

◆ RandomSelection_chosen_vec

vector RandomSelection_chosen_vec

Definition at line 8 of file random.qh.

Referenced by MUTATOR_HOOKFUNCTION(), and RandomSelection_Add().

◆ RandomSelection_totalweight

float RandomSelection_totalweight

Definition at line 3 of file random.qh.

Referenced by RandomSelection_Add(), and RandomSelection_Init().