MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / pickRandom

Function pickRandom

library/xorshift.h:183–195  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

181
182template <typename Container, typename Generator>
183typename Container::const_reference pickRandom(Generator &g, const Container &c)
184{
185 // we can't do index lookups in a list, so we just have to iterate N times
186 if (c.size() == 1)
187 {
188 return *begin(c);
189 }
190 else if (c.empty())
191 {
192 throw std::runtime_error("Trying to randomize within empty container");
193 }
194 return *std::next(begin(c), randBoundsExclusive(g, (unsigned)0, (unsigned)c.size()));
195}
196
197} // namespace OpenApoc

Callers 15

invasionMethod · 0.85
updateCargoMethod · 0.85
alienMovementMethod · 0.85
gotoPortalMethod · 0.85
acquireTargetBuildingMethod · 0.85
updateIdleMethod · 0.85
generatePortalsMethod · 0.85
createBattleMethod · 0.85
placeSectorFunction · 0.85
battlemap.cppFile · 0.85
throwItemMethod · 0.85

Calls 3

randBoundsExclusiveFunction · 0.85
emptyMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected