| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | Copyright 2023, 2025 Joel Svensson svenssonjoel@yahoo.se | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 3 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <extensions.h> | ||
| 19 | #include <lbm_utils.h> | ||
| 20 | |||
| 21 | #ifdef LBM_OPT_RANDOM_EXTENSIONS_SIZE | ||
| 22 | #pragma GCC optimize ("-Os") | ||
| 23 | #endif | ||
| 24 | #ifdef LBM_OPT_RANDOM_EXTENSIONS_SIZE_AGGRESSIVE | ||
| 25 | #pragma GCC optimize ("-Oz") | ||
| 26 | #endif | ||
| 27 | |||
| 28 | |||
| 29 | #define M 268435183 //(1 << 28) | ||
| 30 | #define A 268435043 | ||
| 31 | #define C 268434949 | ||
| 32 | |||
| 33 | |||
| 34 | static lbm_uint random_seed = 177739; | ||
| 35 | |||
| 36 | 102 | static lbm_value ext_seed(lbm_value *args, lbm_uint argn) { | |
| 37 | |||
| 38 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 94 times.
|
102 | LBM_CHECK_ARGN_NUMBER(1); |
| 39 | |||
| 40 | 94 | random_seed = lbm_dec_as_u32(args[0]); | |
| 41 | 94 | return ENC_SYM_TRUE; | |
| 42 | } | ||
| 43 | |||
| 44 | 55386 | static lbm_value ext_random(lbm_value *args, lbm_uint argn) { | |
| 45 | (void)args; | ||
| 46 | (void)argn; | ||
| 47 | 55386 | random_seed = (A * random_seed + C) % M; | |
| 48 | 55386 | return lbm_enc_u(random_seed); | |
| 49 | } | ||
| 50 | |||
| 51 | 66394 | void lbm_random_extensions_init(void) { | |
| 52 | |||
| 53 | 66394 | lbm_add_extension("seed", ext_seed); | |
| 54 | 66394 | lbm_add_extension("random", ext_random); | |
| 55 | 66394 | } | |
| 56 |