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 |
|
28 |
static lbm_value ext_seed(lbm_value *args, lbm_uint argn) { |
29 |
|
|
|
30 |
✗✓ |
28 |
LBM_CHECK_ARGN_NUMBER(1); |
31 |
|
|
|
32 |
|
28 |
random_seed = lbm_dec_as_u32(args[0]); |
33 |
|
28 |
return ENC_SYM_TRUE; |
34 |
|
|
} |
35 |
|
|
|
36 |
|
56 |
static lbm_value ext_random(lbm_value *args, lbm_uint argn) { |
37 |
|
|
(void)args; |
38 |
|
|
(void)argn; |
39 |
|
56 |
random_seed = (A * random_seed + C) % M; |
40 |
|
56 |
return lbm_enc_u(random_seed); |
41 |
|
|
} |
42 |
|
|
|
43 |
|
21672 |
void lbm_random_extensions_init(void) { |
44 |
|
|
|
45 |
|
21672 |
lbm_add_extension("seed", ext_seed); |
46 |
|
21672 |
lbm_add_extension("random", ext_random); |
47 |
|
21672 |
} |