diff options
author | Mike Pall <mike> | 2024-07-04 01:26:29 +0200 |
---|---|---|
committer | Mike Pall <mike> | 2024-07-04 01:26:29 +0200 |
commit | 04dca7911ea255f37be799c18d74c305b921c1a6 (patch) | |
tree | 0979ae369fbb82e7e5fb1c53fcf5cf5955c95f7b /src/lib_math.c | |
parent | 7421a1b33c7ea46f12bba9700c15b5c90253fee0 (diff) | |
download | luajit-04dca7911ea255f37be799c18d74c305b921c1a6.tar.gz luajit-04dca7911ea255f37be799c18d74c305b921c1a6.tar.bz2 luajit-04dca7911ea255f37be799c18d74c305b921c1a6.zip |
Call math.randomseed() without arguments to seed from system entropy.
Reminder: the math.random() PRNG is NOT SUITABLE FOR CRYPTOGRAPHIC USE.
Diffstat (limited to 'src/lib_math.c')
-rw-r--r-- | src/lib_math.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/lib_math.c b/src/lib_math.c index 4539f804..08bb7673 100644 --- a/src/lib_math.c +++ b/src/lib_math.c | |||
@@ -13,6 +13,7 @@ | |||
13 | #include "lualib.h" | 13 | #include "lualib.h" |
14 | 14 | ||
15 | #include "lj_obj.h" | 15 | #include "lj_obj.h" |
16 | #include "lj_err.h" | ||
16 | #include "lj_lib.h" | 17 | #include "lj_lib.h" |
17 | #include "lj_vm.h" | 18 | #include "lj_vm.h" |
18 | #include "lj_prng.h" | 19 | #include "lj_prng.h" |
@@ -183,7 +184,10 @@ LJLIB_PUSH(top-2) /* Upvalue holds userdata with PRNGState. */ | |||
183 | LJLIB_CF(math_randomseed) | 184 | LJLIB_CF(math_randomseed) |
184 | { | 185 | { |
185 | PRNGState *rs = (PRNGState *)(uddata(udataV(lj_lib_upvalue(L, 1)))); | 186 | PRNGState *rs = (PRNGState *)(uddata(udataV(lj_lib_upvalue(L, 1)))); |
186 | random_seed(rs, lj_lib_checknum(L, 1)); | 187 | if (L->base != L->top) |
188 | random_seed(rs, lj_lib_checknum(L, 1)); | ||
189 | else if (!lj_prng_seed_secure(rs)) | ||
190 | lj_err_caller(L, LJ_ERR_PRNGSD); | ||
187 | return 0; | 191 | return 0; |
188 | } | 192 | } |
189 | 193 | ||