Skip to content

Commit 487f8f6

Browse files
committed
Forward random functions to functions in helpers namespace
1 parent c2c303a commit 487f8f6

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

libs/s25main/ai/random.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2005 - 2025 Settlers Freaks (sf-team at siedler25.org)
1+
// Copyright (C) 2005 - 2026 Settlers Freaks (sf-team at siedler25.org)
22
//
33
// SPDX-License-Identifier: GPL-2.0-or-later
44

@@ -29,20 +29,16 @@ inline bool random(unsigned total = 2u, unsigned chance = 1u)
2929
}
3030

3131
template<typename ContainerT>
32-
inline unsigned randomIndex(const ContainerT& container)
32+
unsigned randomIndex(const ContainerT& container)
3333
{
3434
RTTR_Assert(!container.empty());
35-
return randomValue(0u, static_cast<unsigned>(container.size()) - 1u);
35+
return helpers::getRandomIndex(getRandomGenerator(), container.size());
3636
}
3737

3838
template<typename ContainerT>
39-
inline auto randomElement(const ContainerT& container)
39+
auto randomElement(const ContainerT& container)
4040
{
41-
RTTR_Assert(!container.empty());
42-
auto it = container.begin();
43-
if(container.size() > 1u)
44-
std::advance(it, randomIndex(container));
45-
return *it;
41+
return helpers::getRandomElement(getRandomGenerator(), container);
4642
}
4743

4844
} // namespace AI

0 commit comments

Comments
 (0)