GCC Code Coverage Report


Directory: ../src/
File: extensions/random_extensions.c
Date: 2026-10-16 14:49:47
Coverage Exec Excl Total
Lines: 100.0% 11 0 11
Functions: 100.0% 3 0 3
Branches: 100.0% 2 0 2

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 90 static lbm_value ext_seed(lbm_value *args, lbm_uint argn) {
37
38
2/2
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 66 times.
90 LBM_CHECK_ARGN_NUMBER(1);
39
40 66 random_seed = lbm_dec_as_u32(args[0]);
41 66 return ENC_SYM_TRUE;
42 }
43
44 21726 static lbm_value ext_random(lbm_value *args, lbm_uint argn) {
45 (void)args;
46 (void)argn;
47 21726 random_seed = (A * random_seed + C) % M;
48 21726 return lbm_enc_u(random_seed);
49 }
50
51 29167 void lbm_random_extensions_init(void) {
52
53 29167 lbm_add_extension("seed", ext_seed);
54 29167 lbm_add_extension("random", ext_random);
55 29167 }
56