| 1 | /* |
| 2 | * LegacyClonk |
| 3 | * |
| 4 | * Copyright (c) 1998-2000, Matthes Bender (RedWolf Design) |
| 5 | * Copyright (c) 2017-2019, The LegacyClonk Team and contributors |
| 6 | * |
| 7 | * Distributed under the terms of the ISC license; see accompanying file |
| 8 | * "COPYING" for details. |
| 9 | * |
| 10 | * "Clonk" is a registered trademark of Matthes Bender, used with permission. |
| 11 | * See accompanying file "TRADEMARK" for details. |
| 12 | * |
| 13 | * To redistribute this file separately, substitute the full license texts |
| 14 | * for the above references. |
| 15 | */ |
| 16 | |
| 17 | /* Buffered fast and network-safe random */ |
| 18 | |
| 19 | #include <C4Include.h> |
| 20 | #include <C4Random.h> |
| 21 | |
| 22 | // Random3 |
| 23 | |
| 24 | const int FRndRes = 500; |
| 25 | |
| 26 | int32_t FRndBuf3[FRndRes]; |
| 27 | int32_t FRndPtr3; |
| 28 | |
| 29 | void Randomize3() |
| 30 | { |
| 31 | FRndPtr3 = 0; |
| 32 | for (int cnt = 0; cnt < FRndRes; cnt++) FRndBuf3[cnt] = Random(iRange: 3) - 1; |
| 33 | } |
| 34 | |
| 35 | int Rnd3() |
| 36 | { |
| 37 | FRndPtr3++; if (FRndPtr3 == FRndRes) FRndPtr3 = 0; |
| 38 | #ifdef DEBUGREC |
| 39 | AddDbgRec(RCT_Rn3, &FRndPtr3, sizeof(int)); |
| 40 | #endif |
| 41 | return FRndBuf3[FRndPtr3]; |
| 42 | } |
| 43 | |