| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | Copyright 2023 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 | #define M 268435183 //(1 << 28) | ||
| 22 | #define A 268435043 | ||
| 23 | #define C 268434949 | ||
| 24 | |||
| 25 | |||
| 26 | static lbm_uint random_seed = 177739; | ||
| 27 | |||
| 28 | ✗ | static lbm_value ext_seed(lbm_value *args, lbm_uint argn) { | |
| 29 | |||
| 30 | ✗ | LBM_CHECK_ARGN_NUMBER(1); | |
| 31 | |||
| 32 | ✗ | random_seed = lbm_dec_as_u32(args[0]); | |
| 33 | ✗ | return ENC_SYM_TRUE; | |
| 34 | } | ||
| 35 | |||
| 36 | 28 | static lbm_value ext_random(lbm_value *args, lbm_uint argn) { | |
| 37 | (void)args; | ||
| 38 | (void)argn; | ||
| 39 | 28 | random_seed = (A * random_seed + C) % M; | |
| 40 | 28 | return lbm_enc_u(random_seed); | |
| 41 | } | ||
| 42 | |||
| 43 | 17444 | bool lbm_random_extensions_init(void) { | |
| 44 | |||
| 45 | 17444 | bool res = true; | |
| 46 |
2/4✓ Branch 0 taken 17444 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 17444 times.
✗ Branch 4 not taken.
|
17444 | res = res && lbm_add_extension("seed", ext_seed); |
| 47 |
2/4✓ Branch 0 taken 17444 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 17444 times.
✗ Branch 4 not taken.
|
17444 | res = res && lbm_add_extension("random", ext_random); |
| 48 | 17444 | return res; | |
| 49 | } | ||
| 50 |