From c2f41059c71a0c7bfc0b64a7f53334d3bfd0ee76 Mon Sep 17 00:00:00 2001 From: fusion32 Date: Sun, 25 May 2025 22:59:27 -0300 Subject: impl a couple more `util.cc` functions --- src/common.hh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/common.hh') diff --git a/src/common.hh b/src/common.hh index e113e41..58a28c3 100644 --- a/src/common.hh +++ b/src/common.hh @@ -134,6 +134,8 @@ void SetErrorFunction(TErrorFunction *Function); void SetPrintFunction(TPrintFunction *Function); void error(const char *Text, ...) ATTR_PRINTF(1, 2); void print(int Level, const char *Text, ...) ATTR_PRINTF(2, 3); +int random(int Min, int Max); +bool FileExists(const char *FileName); bool isSpace(int c); bool isAlpha(int c); @@ -147,6 +149,22 @@ int stricmp(const char *s1, const char *s2, int Max = INT_MAX); char *findFirst(char *s, char c); char *findLast(char *s, char c); +template +void RandomShuffle(T *Buffer, int Size){ + if(Buffer == NULL){ + error("RandomShuffle: Buffer ist NULL.\n"); + return; + } + + int Max = Size - 1; + for(int Min = 0; Min < Max; Min += 1){ + int Swap = random(Min, Max); + if(Swap != Min){ + std::swap(Buffer[Min], Buffer[Swap]); + } + } +} + struct TReadStream { // VIRTUAL FUNCTIONS // ========================================================================= -- cgit v1.2.3