GCC Code Coverage Report


Directory: ../src/
File: /home/joels/Current/lispbm/src/extensions/random_extensions.c
Date: 2025-10-27 19:12:55
Exec Total Coverage
Lines: 11 11 100.0%
Functions: 3 3 100.0%
Branches: 2 2 100.0%

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